TaskSignal: any() static method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available in Web Workers.

The TaskSignal.any() static method takes an iterable of AbortSignal objects and returns a TaskSignal. The returned task signal is aborted when any of the abort signals is aborted.

When the task signal is aborted, its reason property will be set to the reason of the first signal that is aborted.

Syntax

js
TaskSignal.any(signals)
TaskSignal.any(signals, init)

Parameters

signals

An iterable (such as an Array) of abort signals.

init Optional

Contains optional configuration parameters. Currently only one property is defined:

priority Optional

One of the following:

  • A priority string which is one of user-blocking, user-visible and background.
  • A TaskSignal.

Return value

A TaskSignal instance. It will be aborted when the first signal passed into signals is aborted. When this happens:

  • Its reason property will be set to the reason of the signal that caused this signal to abort.

  • Its priority property will be determined by the priority parameter:

    • If the priority parameter was a string, it will be the value of the string.
    • If the priority parameter was a TaskSignal, it will be the value of that signal's priority.

Examples

Using TaskSignal.any()

This example demonstrates combining both a signal from a TaskController, and a timeout signal from TaskSignal.timeout().

js
const cancelDownloadButton = document.getElementById("cancelDownloadButton");

const userCancelController = new TaskController({
  priority: "user-visible",
});

cancelDownloadButton.addEventListener("click", () => {
  userCancelController.abort();
});

// Timeout after 5 minutes
const timeoutSignal = TaskSignal.timeout(1_000 * 60 * 5);

// This signal will abort when either the user clicks the cancel button or 5 minutes is up whichever is sooner
const combinedSignal = TaskSignal.any([
  userCancelController.signal,
  timeoutSignal,
]);

try {
  const res = await fetch(someUrlToDownload, {
    // Stop the fetch when any of the
    signal: combinedSignal,
  });
  const body = await res.blob();
  // Do something with downloaded content
  // …
} catch (e) {
  if (e.name === "AbortError") {
    // Cancelled by the user
  } else if (e.name === "TimeoutError") {
    // Show user that download timed out
  } else {
    // Other error, e.g. network error
  }
}

Specifications

Specification
Prioritized Task Scheduling
# dom-tasksignal-any

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
any() static method
Chrome – Full support
Chrome 116 (Release date: 2023-08-15)
footnote Full support
Edge – Full support
Edge 116 (Release date: 2023-08-21)
footnote Full support
Firefox – Full support
Firefox 142 (Release date: 2025-08-19)
footnote Full support
Opera – Full support
Opera 102 (Release date: 2023-08-23)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 116 (Release date: 2023-08-15)
footnote Full support
Firefox for Android – Full support
Firefox for Android 142 (Release date: 2025-08-19)
footnote Full support
Opera Android – Full support
Opera Android 78 (Release date: 2023-10-23)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 24 (Release date: 2024-01-25)
footnote Full support
WebView Android – Full support
WebView Android 116 (Release date: 2023-08-15)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also