# AbortSignal.any()

> The `AbortSignal.any()` static JS method returns an `AbortSignal` that aborts when any of the given signals aborts.

## How do I combine an abort signal with a timeout in JavaScript?

The static method that combines several signals into one, which aborts as soon as any of them is aborted. Useful for cancelling a request both by user action and by timeout.

- Topic: Specials
- Type: method
- Browser support: Chrome 116+, Chrome Android 116+, Edge 116+, Firefox 124+, Firefox Android 124+, Safari 17.4+, Safari iOS 17.4+

## Example

Wrong:

```js
const res = await fetch(url, {
  signal: controller.signal,
  timeout: 5000
});
```

Right:

```js
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.

## Common mistakes

- Passing only the timeout signal, so the user's cancel button stops nothing.

## Key points

- The request gets `AbortSignal.any([controller.signal, AbortSignal.timeout(ms)])`, so both cancel and timeout work.
- The `catch` checks `err.name` to tell 'TimeoutError' from 'AbortError'.
- The code does not combine signals by hand with event listeners on each one.

## Interview questions

### What is signal.reason with AbortSignal.any()?

It is the reason of the first input signal that aborted, so you can tell a 'TimeoutError' from a user abort.

### What if one of the input signals is already aborted?

`AbortSignal.any()` returns a signal that is already aborted, with that signal's reason.

## Related cards

- [AbortController](https://wonderium.dev/js/abort-controller.md)
- [AbortSignal.timeout()](https://wonderium.dev/js/abort-signal-timeout.md)
- [fetch()](https://wonderium.dev/js/fetch.md)
- [AbortError](https://wonderium.dev/js/abort-error.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/abort-signal-any
- Last updated: 2026-11-25
