• Returns a promise that resolves after the given amount of time.

    Usage example:

    async function doThingsWithAbort(abort) {
    await foo();
    await sleep(2, abort);
    await foo();
    await sleep(5, abort);
    await foo();
    }

    const abort = new Abort();
    doThingsWithAbort(abort).catch(() => console.log('aborted'))';

    abort.abort();

    Parameters

    • time: number

      The time to sleep, in seconds.

    • Optionalabort: null | ReadonlyAbort

      If provided, will reject the returned promise with the signal's abort reason when aborted. If the signal is already aborted and time is less than or equal to zero, the abort signal takes precedence.

    Returns Promise<void>