Function delay

  • Resolve a Promise after a given amount of milliseconds.

    Parameters

    • ms: number

      Duration in milliseconds for how long the delay should last.

    • options: DelayOptions = {}

      Additional options.

    Returns Promise<void>

    If the optional signal is aborted before the delay duration, and signal.reason is undefined.

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

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

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

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

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