Skip to content

async

Contains utility functions for asynchronous operations.

Interface Description
AsyncMapOptions Options for asyncMap and asyncFlatMap.
InvokeAsyncSafelyAfterDelayParams Parameters for invokeAsyncSafelyAfterDelay.
RetryOptions Options for retryWithTimeout.
RetryWithTimeoutParams Options for retryWithTimeout.
RunWithTimeoutParams Options for runWithTimeout.
SleepParams Parameters for sleep.
TimeoutContext Context provided to the timeout handler.
TimeoutParams Parameters for timeout.
Function Description
addErrorHandler Adds an error handler to a Promise that catches any errors and emits an async error event.
asyncFilter Filters an array asynchronously, keeping only the elements that satisfy the provided predicate function.
asyncFilterInPlace Filters an array asynchronously in place, keeping only the elements that satisfy the provided predicate function.
asyncFlatMap Maps over an array asynchronously, applying the provided callback function to each element, and then flattens the results into a single array.
asyncMap Maps over an array asynchronously, applying the provided callback function to each element. Without options, every callback starts at once. With a concurrency, at most that many callbacks run at a time, each new one starting as soon as a running one settles, in array order. With options, the first callback that throws stops new callbacks from starting, and the returned promise rejects with that error at once. Aborting the abortSignal does the same with the signal’s reason. Callbacks already running are not interrupted: pass the same signal into them if they should stop too. Bounded concurrency adapts the worker pool of radashi’s parallel (MIT, see THIRD-PARTY-NOTICES.md).
chain Chains a promise with another promise.
convertAsyncToSync Converts an asynchronous function to a synchronous one by automatically handling the Promise rejection.
convertSyncToAsync Converts a synchronous function to an asynchronous one by wrapping it in a Promise.
handleSilentError Handles a silent error.
ignoreError Ignores an error that is thrown by an asynchronous function.
invokeAsyncSafely Invokes a Promise and safely handles any errors by catching them and emitting an async error event.
invokeAsyncSafelyAfterDelay Invokes an asynchronous function after a delay.
isTerminationOnTimeoutEnabled Gets whether a runWithTimeout call without its own onTimeout terminates the operation when it times out.
marksAsTerminateRetry Marks an error to terminate retry logic.
neverEnds An async function that never ends.
nextTickAsync Gets the next tick.
normalizePromisable Converts to native promisable, converting PromiseLike (aka Thenable) to a native Promise.
promiseAllAsyncFnsSequentially Executes async functions sequentially.
promiseAllSequentially Executes promises sequentially.
queueMicrotaskAsync Gets the next queue microtask.
requestAnimationFrameAsync Gets the next request animation frame.
retryWithTimeout Retries the provided function until it returns true or the timeout is reached.
runWithTimeout Executes a function with a timeout. If the function does not complete within the specified time, it is considered to have timed out. Without an onTimeout, a timed-out function is terminated, unless the getTerminateOnTimeoutDebugSwitch debug switch is off, in which case it is allowed to run indefinitely.
setImmediateAsync Gets the next set immediate.
setTerminationOnTimeoutEnabled Sets whether a runWithTimeout call without its own onTimeout terminates the operation when it times out.
setTimeoutAsync Delays execution for a specified number of milliseconds.
sleep Delays execution for a specified number of milliseconds.
timeout Returns a Promise that rejects after the specified timeout period.
toArray Converts an AsyncIterableIterator to an array by consuming all its elements.
Type Description
AsyncFlatMapOptions Options for asyncFlatMap: the same as AsyncMapOptions.
PromiseResolve A type representing a function that resolves a Promise.