← Back to release summary

AbortSignal.any()

Category
DOM
Type
New or changed feature
Status
Enabled by default (Chrome 116)
Intent stage
Prepare to ship

Summary

AbortSignal.any(signals) returns a signal that is aborted when any of the source signals are aborted. Developers can use this to combine independent abort sources, e.g. timeouts specified with AbortSignal.timeout() and signals associated with user input, and pass them to async APIs like fetch().

Motivation

Some async operations may be aborted due to a variety of reasons, e.g. due to timeout or user cancellation. And while nothing prevents an AbortController's abort method from being invoked for multiple reasons, combining signals enables separate layers of control, where the scope of cancellation may vary. Since AbortSignal-accepting APIs only accept a single signal, combining signals currently needs to be done in userland using event listeners, but this is complicated by challenges around memory leaks. AbortSignal.any() makes it easy to combine signals, and by allowing the UA to maintain these relationships, the UA can free related resources when safe to do so.

Standards & signals

Docs: https://docs.google.com/document/d/1LvmsBLV85p-PhSGvTH-YwgD6onuhh1VXLg8jPlH32H4/edit#heading=h.xp6e50wyimb4

Explainers: https://github.com/shaseley/abort-signal-any/blob/main/README.md

View on chromestatus.com