timeout
Wraps a promise to reject with a TimeoutError if it does not resolve within the specified duration.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
promise | Promise<T> | The promise to wrap |
ms | number | Timeout duration in milliseconds |
Returns
Section titled “Returns”Promise<T> — A promise that rejects with TimeoutError if the timeout is exceeded
Examples
Section titled “Examples”Reject a slow promise
Section titled “Reject a slow promise”Throws a TimeoutError if the promise does not resolve in time.
Resolve fast promise normally
Section titled “Resolve fast promise normally”Returns the value if the promise resolves before the timeout.
