delay

import { delay } from "jsr:@ende/async";

function

function delay(ms: number, options: DelayOptions = [UNSUPPORTED]): Promise<void>

Resolve a Promise after a given amount of milliseconds.

If the optional signal is aborted before the delay duration, the returned promise rejects with the signal's reason. If no reason is provided to abort(), the browser's default DOMException with name "AbortError" is used.

ms: number

Duration in milliseconds for how long the delay should last.

options: DelayOptions = [UNSUPPORTED]

Additional options.

Example: Basic usage

import { delay } from "@ende/async/delay";

// ...
const delayedPromise = delay(100);
const result = await delayedPromise;
// ...

Example: Disable persistence

Setting persistent to false will allow the process to continue to run as long as the timer exists.

import { delay } from "@ende/async/delay";

// ...
await delay(100, { persistent: false });
// ...

Source