Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 857 Bytes

link-controllers.md

File metadata and controls

29 lines (19 loc) · 857 Bytes

linkControllers(...controllers)

It can link multiple controllers so that when one aborts, they all abort with the same reason.

import {linkControllers} from 'abort-utils';

// First signal
const userAction = new AbortController();

// Second signal
const timeout = AbortSignal.timeout(100);

// Merged signal
const mergedSignal = mergeSignals(timeout, userAction.signal);
mergedSignal.addEventListener('abort', () => {
	console.log('One of the signals was aborted', mergedSignal.reason);
});

controllers

Type: AbortController, AbortSignal

The controllers or signals to listen to and abort. linkControllers only makes sense if you pass at least one controller because abort signals cannot be aborted by this function.

If you only have signals, prefer mergeSignals instead.