You have a fetch request that needs to stop if either a user clicks cancel or a 5 second timeout fires. In the past, wiring up both conditions meant messy boolean flags, manual promise wrapping, or third party libraries. The new AbortSignal.any() static method changes that. It lets you combine multiple AbortSignal instances into one, so a single signal can react to the first cancellation reason that happens. If you write async JavaScript and want cleaner abort logic, this API is worth your attention.
AbortSignal.any() JavaScript combines multiple abort signals into one composite signal. It fires when any child signal fires, making it easier to cancel async operations for multiple reasons like user requests, timeouts, or parent cancellations. This reduces boilerplate and keeps your async code readable. Use it with fetch, promises, and any API that accepts an AbortSignal.
Why you need composite abort signals
Modern JavaScript relies on AbortController and AbortSignal for cancellation. You pass a signal to fetch() or a custom promise, then call controller.abort() when you need to stop. That works great for one reason. But real applications have multiple cancellation triggers.
Consider a file upload component. You might want to cancel because:
- The user clicked a cancel button.
- A global timeout expired.
- The parent request was aborted.
Without AbortSignal.any(), you end up writing code that checks each condition separately. You might create a wrapper promise that rejects on any of those events. Or you might poll a shared boolean. Neither approach is elegant.
AbortSignal.any() solves this by accepting an iterable of signals and returning a new signal that aborts when the first child signal aborts. The composite signal carries the reason from whichever child triggered first.
How AbortSignal.any() works
The method signature is simple:
AbortSignal.any(signals);
It takes an iterable of AbortSignal objects and returns a new AbortSignal. The returned signal will be in an aborted state if any of the provided signals are already aborted. Otherwise, it becomes aborted as soon as any child signal is aborted.
Here is a basic example:
const controller1 = new AbortController();
const controller2 = new AbortController();
const combined = AbortSignal.any([controller1.signal, controller2.signal]);
// Later, either of these will abort the combined signal
controller1.abort('User cancelled');
// or
controller2.abort('Timeout');
You can pass the combined signal to fetch() or any other function that accepts an AbortSignal. This keeps your calling code clean.
Practical example: race between timeout and user cancel
Imagine you are building a search input that sends a fetch request. You want to cancel the request if the user types something new or if the request takes too long. Here is how you would do it with AbortSignal.any():
function searchWithCancel(url, timeoutMs) {
const timeoutController = new AbortController();
const cancelController = new AbortController();
const timeoutId = setTimeout(() => {
timeoutController.abort('Request timed out');
}, timeoutMs);
const combinedSignal = AbortSignal.any([
timeoutController.signal,
cancelController.signal
]);
const promise = fetch(url, { signal: combinedSignal })
.then(response => {
clearTimeout(timeoutId);
return response.json();
})
.catch(err => {
clearTimeout(timeoutId);
throw err;
});
// Return both the promise and a way to cancel
return {
promise,
cancel: () => cancelController.abort('User cancelled')
};
}
const search = searchWithCancel('/api/data', 5000);
// User changes input, so we cancel
search.cancel();
No boolean flags. No wrapping fetch in a separate promise. The composite signal handles both conditions.
Common patterns and mistakes
The table below shows typical use cases and the pitfalls to avoid.
| Pattern | What to do | Common mistake |
|---|---|---|
| Combining timeout with user cancel | Use AbortSignal.any() with one controller per reason |
Creating one controller and calling abort multiple times with different reasons |
| Parent-child cancellation | Pass parent signal into any() alongside child signals |
Manually checking parentSignal.aborted in every child |
| Multiple fetch requests sharing one cancel | Create one composite signal and pass it to all fetches | Creating separate controllers for each fetch and forgetting to wire them together |
| Reusing a composite signal | Create a new composite each time you start an operation | Reusing the same composite signal after it has been aborted |
One important detail: once a signal is aborted, it stays aborted. You cannot reuse it. If you need to run the same operation again, create fresh controllers and a fresh composite signal.
Numbered process: migrating legacy cancel logic
If you have existing code that uses manual flags or wrapper promises, here is a step by step process to migrate to AbortSignal.any().
- Identify all cancellation triggers in your function. Common ones are timeouts, user actions, and parent component teardown.
- Create one
AbortControllerper trigger. Name them clearly, liketimeoutController,cancelController,parentController. - Create a composite signal using
AbortSignal.any([...controllers.map(c => c.signal)]). - Pass the composite signal to your async operation (fetch, promise, etc.).
- Wire each trigger to call
.abort(reason)on its respective controller. - Remove any old boolean flags, wrapper promises, or polling code.
- Test each trigger independently to confirm the operation cancels with the correct reason.
Combining with other AbortSignal features
AbortSignal has more than just any(). You also have AbortSignal.timeout() which creates a signal that aborts after a given duration. You can combine it with any() for even more flexibility.
const userController = new AbortController();
const timeoutSignal = AbortSignal.timeout(3000);
const combined = AbortSignal.any([userController.signal, timeoutSignal]);
fetch('/data', { signal: combined });
This is equivalent to the earlier example but uses the built-in timeout signal instead of a manual setTimeout. It is cleaner and less error prone.
Expert advice: Use
AbortSignal.timeout()instead of manual timers when you only need a timeout. It removes the risk of forgetting to clear the timer and integrates directly with the signal system.
When not to use AbortSignal.any()
This method is not a silver bullet. If you need to cancel different operations for different reasons independently, a single composite signal will not work. Each operation needs its own signal.
Also, if you are working with a codebase that does not support AbortSignal at all, you will need to add that support first. The any() method only works if the functions you call accept a signal parameter.
For cases where you need to react to cancellation with custom cleanup logic, you can attach an event handler to the composite signal:
combined.addEventListener('abort', (event) => {
console.log('Operation cancelled because:', combined.reason);
// Run cleanup here
});
How this fits into modern async JavaScript
The trend in 2026 is toward better async primitives. AbortSignal.any() is part of that shift. It reduces the need for promise race patterns like Promise.race() combined with rejection on cancel. It also works naturally with the fetch API, Request objects, and any custom async function that accepts a signal.
If you are building libraries or frameworks, accepting an AbortSignal parameter is becoming a best practice. Users of your library can then compose signals using any() to fit their application logic. This makes your library more flexible without adding complexity.
For more on modern JavaScript patterns, check out our guide on how to optimize web performance with modern JavaScript techniques. It covers related async improvements that pair well with composite signals.
Putting AbortSignal.any() into practice
The best way to learn is to refactor an existing piece of code. Pick a function in your current project that uses a timeout and a cancel button. Replace the manual logic with AbortSignal.any(). You will likely remove 10 to 15 lines of boilerplate and end up with code that is easier to read.
Here is a checklist to guide your refactor:
- Replace wrapper promises with direct signal passing.
- Remove boolean flags that track cancellation state.
- Use
AbortSignal.timeout()for timeouts instead of setTimeout. - Name your controllers based on the cancellation reason.
- Attach abort event listeners only when you need side effects.
If you are new to AbortController in general, start with a single signal before composing multiple. Once you are comfortable, AbortSignal.any() will feel natural.
The future of cancellation in JavaScript
The JavaScript ecosystem continues to embrace structured concurrency. AbortSignal.any() is a building block for more advanced patterns like structured cancellation scopes. You can already see this in frameworks that use hierarchical controllers for request lifecycles.
As more APIs adopt AbortSignal, the need for composite signals grows. Expect to see AbortSignal.any() used in database drivers, WebSocket libraries, and even UI frameworks in the coming years.
For a look at other emerging APIs, read our article on 10 new web APIs that will simplify your code in 2026. It covers several additions that pair well with the abort signal family.
Start cleaning up your async code today
You do not need to wait for a big rewrite. The next time you write a fetch call with a timeout, reach for AbortSignal.any(). The pattern is small, but the impact on code clarity is noticeable. Your future self, and anyone who reads your code, will thank you for removing the clutter.
Give it a try in a side project first. Wire up a cancel button and a timeout. See how the composite signal behaves. Once you see it work, you will start looking for other places to apply it. That is the mark of a good API: it makes you want to use it everywhere.