Skip to content

async

Contains utility functions for asynchronous operations.

InterfaceDescription
InvokeAsyncSafelyAfterDelayParamsParameters for invokeAsyncSafelyAfterDelay.
RetryOptionsOptions for retryWithTimeout.
RetryWithTimeoutParamsOptions for retryWithTimeout.
RunWithTimeoutParamsOptions for runWithTimeout.
SleepParamsParameters for sleep.
TimeoutContextContext provided to the timeout handler.
TimeoutParamsParameters for timeout.
FunctionDescription
addErrorHandlerAdds an error handler to a Promise that catches any errors and emits an async error event.
asyncFilterFilters an array asynchronously, keeping only the elements that satisfy the provided predicate function.
asyncFilterInPlaceFilters an array asynchronously in place, keeping only the elements that satisfy the provided predicate function.
asyncFlatMapMaps over an array asynchronously, applying the provided callback function to each element, and then flattens the results into a single array.
asyncMapMaps over an array asynchronously, applying the provided callback function to each element.
chainChains a promise with another promise.
convertAsyncToSyncConverts an asynchronous function to a synchronous one by automatically handling the Promise rejection.
convertSyncToAsyncConverts a synchronous function to an asynchronous one by wrapping it in a Promise.
disableAsyncOperationTrackingDisables tracking previously enabled via enableAsyncOperationTracking and forgets any currently-tracked operations.
enableAsyncOperationTrackingEnables tracking of fire-and-forget operations scheduled via invokeAsyncSafely (and therefore convertAsyncToSync). While enabled, each scheduled operation is recorded until it settles so that tests can await them all via waitForAllAsyncOperations, removing the need to override invokeAsyncSafely / convertAsyncToSync in tests. Tracking is disabled by default, so production code carries no bookkeeping overhead. Intended to be enabled in test environments only.
handleSilentErrorHandles a silent error.
ignoreErrorIgnores an error that is thrown by an asynchronous function.
invokeAsyncSafelyInvokes a Promise and safely handles any errors by catching them and emitting an async error event.
invokeAsyncSafelyAfterDelayInvokes an asynchronous function after a delay.
isAsyncOperationTrackingEnabledChecks whether async-operation tracking is currently enabled (see enableAsyncOperationTracking).
marksAsTerminateRetryMarks an error to terminate retry logic.
neverEndsAn async function that never ends.
nextTickAsyncGets the next tick.
normalizePromisableConverts to native promisable, converting PromiseLike (aka Thenable) to a native Promise.
promiseAllAsyncFnsSequentiallyExecutes async functions sequentially.
promiseAllSequentiallyExecutes promises sequentially.
queueMicrotaskAsyncGets the next queue microtask.
requestAnimationFrameAsyncGets the next request animation frame.
retryWithTimeoutRetries the provided function until it returns true or the timeout is reached.
runWithTimeoutExecutes a function with a timeout. If the function does not complete within the specified time, it is considered to have timed out. If DEBUG=obsidian-dev-utils:Async:runWithTimeout is set, the execution is not terminated after the timeout and the function is allowed to run indefinitely.
setImmediateAsyncGets the next set immediate.
setTimeoutAsyncDelays execution for a specified number of milliseconds.
sleepDelays execution for a specified number of milliseconds.
timeoutReturns a Promise that rejects after the specified timeout period.
toArrayConverts an AsyncIterableIterator to an array by consuming all its elements.
waitForAllAsyncOperationsWaits for all fire-and-forget operations tracked since enableAsyncOperationTracking was called to settle. Operations scheduled while awaiting are also awaited, so cascading fire-and-forget chains are fully drained.
TypeDescription
PromiseResolveA type representing a function that resolves a Promise.