Promise Helpers
Utility functions for working with promise operations.
Functions
Section titled “Functions”| Function | Description |
|---|---|
consoleLogPromise |
Returns a function that logs data to the console and passes it through. |
createMutex |
Creates a mutex: a lock allowing at most one holder at a time, queueing excess `acquire()` callers in FIFO order. |
createSemaphore |
Creates a semaphore limiting concurrent access to `permits` holders at a time, queueing excess `acquire()` callers in F… |
defer |
Runs an async function and guarantees that all deferred callbacks are executed afterwards, in LIFO order (last register… |
delay |
Creates a promise that resolves after specified delay |
falsyPromiseOrThrow |
Returns a function that passes through falsy data or throws an error. |
guard |
Wraps a function so that if it throws, a default value is returned instead of propagating the error. |
meaningPromiseOrThrow |
Returns a function that passes through meaningful data or throws an error. |
parallel |
Runs an array of async functions with a concurrency limit. |
parallelSettle |
Runs an array of async functions with a concurrency limit, partitioning the outcomes instead of rejecting on the first … |
resolveRecord |
Resolves an array of keys into a record by calling an async mapper for each key. |
retry |
Retries a promise-returning function up to maxAttempts times |
safeFetch |
Wraps `fetch` with built-in error handling: returns `null` when the request fails (network error, non-OK status, or par… |
settle |
Runs an array of promises concurrently and partitions the outcomes instead of rejecting on the first failure, unlike `P… |
timeout |
Wraps a promise to reject with a `TimeoutError` if it does not resolve within the specified duration. |
truthyPromiseOrThrow |
Returns a function that passes through truthy data or throws an error. |
tryit |
Wraps a function so it never throws. |
withResolvers |
native JS Promise.withResolvers() (ES2024) |
