Wraps an existing promise with a rejection deadline.
If the wrapped promise does not settle within ms milliseconds, the returned
promise rejects with an AbortError. If the promise settles before the
deadline, the timer is cancelled and its result is forwarded transparently.
Optionally accepts an AbortSignal — if the signal fires before the
deadline, the returned promise rejects immediately.
Example:
// Reject after 5 seconds constdata = awaittimeout(fetch('/api/data'), 5_000);
Wraps an existing promise with a rejection deadline.
If the wrapped promise does not settle within
msmilliseconds, the returned promise rejects with anAbortError. If the promise settles before the deadline, the timer is cancelled and its result is forwarded transparently.Optionally accepts an
AbortSignal— if the signal fires before the deadline, the returned promise rejects immediately.Example: