1.0.0-rc.3 • Published 9 months ago

aggregated-abortcontroller v1.0.0-rc.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

AggregatedAbortController

A extendable AbortController with link aggregation with existing AbortController or AbortSignal.

Install

npm install aggregated-abortcontroller

Usage

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();

API

The AggregatedAbortController extends the AbortController and has the same API.

The following methods are added as extras to the AggregatedAbortController:

AggregatedAbortController

const aggregatedController = new AggregatedAbortController(signals: (AbortSignal | AbortController)[])

AggregatedAbortController.attach()

Attach a signal to this controller.

aggregatedController.attach(AbortSignal) // => boolean

AggregatedAbortController.detach()

Detach a signal from this controller.

aggregatedController.detach(AbortSignal) // => boolean

AggregatedAbortController.detachAll()

Detach all signals from this controller.

aggregatedController.detachAll() // => void

License

Licensed under MIT License.

1.0.0-rc.3

9 months ago

1.0.0-rc.2

9 months ago

1.0.0-rc.1

9 months ago