Skip to content

@vgerbot/async

Build async workflows with cancellation, concurrency limits, control-flow primitives, and task executors.

@vgerbot/async gives TypeScript applications a focused toolkit for async orchestration. It combines cancellable task handles, collection helpers, dependency-aware control flow, queues, and reusable task executors behind a consistent API.

Cancellable by default

Use CancellableHandle, CancellableToken, CancelError, timeouts, retries, and linked AbortSignal flows to stop async work predictably.

Control async flow

Run dependency graphs with auto, process jobs with queue, compose steps with waterfall, and coordinate tasks with parallel, series, race, and more.

Limit concurrency

Apply concurrency to collections, queues, pools, rate limits, and priority pools without rewriting scheduling logic.

Small utilities

Memoize cancellable functions, compose async functions, debounce or throttle work, and bridge sync functions into cancellable handles.

Terminal window
pnpm add @vgerbot/async
import { auto, queue, memoize } from "@vgerbot/async";
const getUser = memoize(async (id: number, token) => {
const response = await token.wrap(fetch(`/api/users/${id}`));
return response.json();
});
const jobs = queue(async (id: number) => {
const handle = getUser(id);
return handle.promise;
}, { concurrency: 2 });
const workflow = auto({
user: async () => jobs.push(1),
settings: [["user"], async ({ user }) => fetch(`/api/settings/${user.id}`)],
});
const result = await workflow.promise;