@silyze/combine-abort-signals
v1.0.0
Published
A function that combines multiple abort signals into one
Readme
Combine Abort Signals
A function that combines multiple abort signals into one.
Install
npm install @silyze/combine-abort-signalsUsage
Import and use it in your project:
import combineAbortSignals from "@silyze/combine-abort-signals";
const first = new AbortController();
const second = new AbortController();
const signal = combineAbortSignals(first.signal, second.signal);
if (Math.random() < 0.5) {
first.abort();
} else {
second.abort();
}
if (signal.aborted) {
console.log("OK!");
} else {
throw new Error("This should be unreachable");
}API
combineAbortSignals(...signals: (AbortSignal | undefined)[]): AbortSignal
Creates a new AbortSignal that is aborted when any of the provided signals is aborted.
- Accepts
undefinedentries and ignores them. - Aborts with the same reason as the first signal to abort.
- Useful for combining cancellation logic from multiple sources.
