JavaScript Tested
Sleep / delay with a Promise
Pause an async function for a number of milliseconds, with optional cancellation through AbortSignal.
Loading snippets…
7 snippets
Pause an async function for a number of milliseconds, with optional cancellation through AbortSignal.
Process a large list with at most N promises in flight at once, preserving result order.
Retry a failing promise-returning function with growing, jittered delays and a retry predicate.
Re-run a flaky function a limited number of times with growing delays, only for chosen exception types.
Iterate cursor-paginated API results with for await, loading pages lazily and stopping early when needed.
Abort slow HTTP requests with AbortSignal.timeout and turn non-2xx responses into real errors.
Delay a function call until the caller has stopped invoking it for a given time, with cancel support.