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. |
Constants
| Name | Description |
|---|---|
DEFAULT_BG_RUNNER_WAIT_FN | Default wait function used by BackgroundRunner.runLater. |
DEFAULT_BEFORE_RETRY | Default beforeRetry callback using exponential backoff with full jitter. |
Errors
| Name | Description |
|---|---|
TimeoutError | Thrown when an async operation exceeds the configured timeout. |
AbortedError | Thrown when an async operation is aborted via an AbortSignal. |
Typings
| Name | Description |
|---|---|
IPromiseResolver<T> | Function type for a Promise resolver. |
IPromiseRejecter<T> | Function type for a Promise rejecter. |
IWithTimeoutOptions<T> | Options for withTimeout. |
IWithAbortSignalOptions<T> | Options for withAbortSignal. |
IRetryOptions<T> | Options for autoRetry. |
IRetryContext | Context passed to each retry attempt. |
IBeforeRetryCallback | Type for the beforeRetry callback. |
IRetryDelayGenerator | Type for a retry delay generator function. |
IRetryDelayJitterFunction | Type for a jitter function applied to retry delays. |
IRetryDelayOptions | Options for compositeRetryDelayGenerator. |
IFiberContext<T> | Context passed to a fiber execution function. |
IFiberExecution<T> | Fiber execution function type. |
IFiberOptions<T> | Constructor options for FiberController. |
IBackgroundRunnerOptions | Constructor options for BackgroundRunner. |
IBackgroundRunnerEvents | Events emitted by BackgroundRunner. |