timeout es-toolkit
Returns a Promise that throws a TimeoutError after the specified time.
Usage
timeout(ms, options?)
Use timeout when you want to throw a timeout error after a specific time has passed. It's useful when used together with Promise.race() to set time limits on tasks.
You can use it with Promise.race() to set time limits on tasks:
You can also use it when you want to fail the entire operation if any of multiple asynchronous tasks don't complete within the specified time.
You can pass an AbortSignal to cancel the timeout. Unlike delay, aborting does not reject the Promise. Because timeout only exists to lose a Promise.race(), cancelling it leaves the Promise pending so the operation it guards can finish without the time limit.
Parameters
The amount of time in milliseconds until the TimeoutError is thrown.
Timeout options.
signal(AbortSignal, optional): An AbortSignal to cancel the timeout. When aborted, the returned Promise stays pending and never rejects.
Returns
Returns a Promise that rejects with a TimeoutError after the specified time. If the AbortSignal is aborted first, the Promise never settles.
Errors
Throws TimeoutError after the specified time has passed. Aborting the AbortSignal does not throw; it cancels the timeout so the Promise stays pending.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.