Namespace Async
Async utilities for timeouts, abortable operations, automatic retry, structured concurrency, and background task management.
Install
Use this namespace only:
bash
npm i @litert/utils-asyncOr install the full bundle:
bash
npm i @litert/utilsAnd then import from it.
ts
import * as LibUtils from '@litert/utils';
LibUtils.Async.autoRetry(...);
// or
import { Async as LibAsync } from '@litert/utils';
LibAsync.autoRetry(...);Exports
Classes
| Name | Description |
|---|---|
AbortTimeoutController | An AbortController that automatically fires after a configurable timeout. |
PromiseController<T> | Decouples a Promise's resolve/reject functions from the promise itself. |
FiberController<T> | Controls an async fiber lifecycle: run, sleep, resume, and abort. |
BackgroundRunner | Runs async callbacks in the background without blocking the calling fiber. |
Functions
| Name | Description |
|---|---|
sleep | Delays for the given number of milliseconds, optionally abortable. |
withTimeout | Wraps a Promise or async function with a timeout. |
withAbortSignal | Wraps a Promise or async function with an AbortSignal. |
autoRetry | Automatically retries a failing async function with configurable backoff. |
createExponentialBackoffDelayGenerator | Creates an exponential backoff delay generator. |
fullJitter | Applies a full-jitter effect to a retry delay. |
equalJitter | Applies an equal-jitter effect to a retry delay. |
compositeRetryDelayGenerator | Composes a delay generator with jitter and a maximum delay cap. |
Errors
| Name | Description |
|---|---|
E_TIMEOUT | Thrown when an async operation exceeds the configured timeout. |
E_ABORTED | Thrown when an async operation is aborted via an AbortSignal. |
E_FIBER_EXITED | Thrown when attempting to interact with a fiber that has already exited. |
Typings
See Typings.md for shared interfaces.
| Name | Description |
|---|---|
IPromiseResolver<T> | Function type for a Promise resolver. |
IPromiseRejecter<T> | Function type for a Promise rejecter. |
IRetryDelayGenerator | Type for a retry delay generator function. |
IRetryDelayJitterFunction | Type for a jitter function applied to retry delays. |
IRetryDelayOptions | Options for compositeRetryDelayGenerator. |