Skip to content

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-async

Or install the full bundle:

bash
npm i @litert/utils

And 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

NameDescription
AbortTimeoutControllerAn 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.
BackgroundRunnerRuns async callbacks in the background without blocking the calling fiber.

Functions

NameDescription
sleepDelays for the given number of milliseconds, optionally abortable.
withTimeoutWraps a Promise or async function with a timeout.
withAbortSignalWraps a Promise or async function with an AbortSignal.
autoRetryAutomatically retries a failing async function with configurable backoff.
createExponentialBackoffDelayGeneratorCreates an exponential backoff delay generator.
fullJitterApplies a full-jitter effect to a retry delay.
equalJitterApplies an equal-jitter effect to a retry delay.
compositeRetryDelayGeneratorComposes a delay generator with jitter and a maximum delay cap.

Errors

NameDescription
E_TIMEOUTThrown when an async operation exceeds the configured timeout.
E_ABORTEDThrown when an async operation is aborted via an AbortSignal.
E_FIBER_EXITEDThrown when attempting to interact with a fiber that has already exited.

Typings

See Typings.md for shared interfaces.

NameDescription
IPromiseResolver<T>Function type for a Promise resolver.
IPromiseRejecter<T>Function type for a Promise rejecter.
IRetryDelayGeneratorType for a retry delay generator function.
IRetryDelayJitterFunctionType for a jitter function applied to retry delays.
IRetryDelayOptionsOptions for compositeRetryDelayGenerator.