AbortSignal.any()
A function that combines several signals into one that aborts as soon as any of them does.
In more detail
The combined signal's reason is the reason of whichever input aborted first. AbortSignal.any([userCancel.signal, AbortSignal.timeout(5000)]) cancels on a click or a deadline, whichever comes first, replacing hand-written Promise.race logic.
Related terms
- AbortSignal — The object from an AbortController that tells work it has been cancelled, through its aborted flag, its reason and an abort event.
- AbortSignal.timeout() — A function that returns a signal which aborts itself after a given number of milliseconds, with a TimeoutError.
- Promise.race() — A function that returns a promise that settles as soon as the first of several promises settles.
Taught in
- Cancellation With AbortController And Async Signal Propagation — Frontend Architecture & Web Platform