Races promise against a timeout. Rejects with a TimeoutError if ms elapses first.
promise
TimeoutError
ms
The promise to race.
Timeout duration in milliseconds.
const data = await withTimeout(fetch("/api"), 5000)// throws if the fetch takes longer than 5 seconds Copy
const data = await withTimeout(fetch("/api"), 5000)// throws if the fetch takes longer than 5 seconds
Races
promiseagainst a timeout. Rejects with aTimeoutErrorifmselapses first.