A extendable AbortController
with link aggregation with existing AbortController
or AbortSignal
.
npm install aggregated-abortcontroller
import AggregatedAbortController from 'aggregated-abortcontroller';
// Create a new AbortController
const controller = new AbortController();
// Create a new AggregatedAbortController that aggregates the signal of the AbortController
const aggregatedController = new AggregatedAbortController([controller.signal]);
// Register a listener to the aggregated signal
aggregatedController.signal.addEventListener('abort', () => {
console.log('aborted');
});
// Calling abort on the linked signal will also abort the aggregated signal
controller.abort(); // => 'aborted'
// But calling abort on the aggregated signal will not abort the linked signal
aggregatedController.abort();
The AggregatedAbortController
extends the AbortController
and has the same API.
The following methods are added as extras to the AggregatedAbortController
:
const aggregatedController = new AggregatedAbortController(signals: (AbortSignal | AbortController)[])
Attach a signal to this controller.
aggregatedController.attach(AbortSignal) // => boolean
Detach a signal from this controller.
aggregatedController.detach(AbortSignal) // => boolean
Detach all signals from this controller.
aggregatedController.detachAll() // => void
Licensed under MIT License.