function timeout
timeout<T = void>(
milliseconds: number,
value?: T
): Promise<T>

Creates a promise that resolves after a specified delay.

Useful for pausing execution in async workflows, throttling operations, or simulating delays in tests.

Examples

Example 1

await timeout(1000);

Example 2

const result = await timeout(1000, "done"); console.log(result); // "done"

Type Parameters

T = void

Parameters

milliseconds: number

Time to wait in milliseconds.

optional
value: T

Optional value to resolve with.

Return Type

Promise<T>

A promise that resolves after the delay.

Usage

import { timeout } from ".";