Function: sleep()
sleep(
ms,signal?):Promise<void>
Promisified setTimeout that wakes up early (and rejects with
signal.reason) when signal aborts mid-wait. Short-circuits to a
rejected promise when the signal is already aborted on entry, so the
abort path is consistent regardless of whether the wait actually
started.
Use as the building block for any “wait, but cancel cleanly” pattern -
inter-poll backoff, pacing loops, retry timers, long-poll budgets - so
cancellation always rejects with the caller’s signal.reason rather
than silently resolving after the timer expires.
Parameters
Section titled “Parameters”number
signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example”await sleep(250, req.signal);