@lebedevna/delay
v0.1.0
Published
A disposable, abortable delay for TypeScript and JavaScript.
Maintainers
Readme
@lebedevna/delay
A disposable, abortable delay for TypeScript and JavaScript.
import { delay } from "@lebedevna/delay";
await delay(500);Installation
pnpm add @lebedevna/delayThe duration is expressed in milliseconds. delay returns a DisposablePromise<void>, which behaves like a regular promise.
Abort a delay
Pass an AbortSignal to end the delay early:
const controller = new AbortController();
const waiting = delay(5_000, { signal: controller.signal });
controller.abort();
await waiting;Aborting resolves the promise with undefined and clears the pending timer. It does not reject with an AbortError. If the signal is already aborted, the promise resolves immediately.
Asynchronous disposal
DisposablePromise implements Symbol.asyncDispose, so a delay can be used with await using:
await using waiting = delay(500);Disposal awaits the promise; it does not cancel the delay. Use an AbortSignal when you need early completion.
API
delay(ms, options?)
Creates a DisposablePromise<void> that resolves after ms milliseconds.
type Options = {
signal?: AbortSignal;
};DisposablePromise<T>
A Promise<T> subclass with an asynchronous dispose method that waits for the promise to settle.
Agent skill
The package ships a TanStack Intent-compatible skill for coding agents. In a project that depends on this package, discover or load it with:
pnpm dlx @tanstack/intent@latest list
pnpm dlx @tanstack/intent@latest load @lebedevna/delay#delayDevelopment
pnpm install
pnpm test
pnpm run validate:skillsLicense
MIT
