Loading...
const res = await fetch(url, {
signal: controller.signal,
timeout: 5000
});const signal = AbortSignal.any([
controller.signal,
AbortSignal.timeout(5000)
]);
const res = await fetch(url, { signal });fetch() has no timeout option; AbortSignal.any() aborts on whichever comes first, user cancel or timeout.
AbortSignal.any([controller.signal, AbortSignal.timeout(ms)]), so both cancel and timeout work.catch checks err.name to tell 'TimeoutError' from 'AbortError'.It is the reason of the first input signal that aborted, so you can tell a 'TimeoutError' from a user abort.
AbortSignal.any() returns a signal that is already aborted, with that signal's reason.