Package Exports
- any-signal
- any-signal/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (any-signal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
any-signal
Combines an array of AbortSignals into a single signal that is aborted when any signal is.
Install
npm install any-signalUsage
const anySignal = require('any-signal')
const userController = new AbortController()
const timeoutController = new AbortController()
const combinedSignal = anySignal([userController.signal, timeoutController.signal])
combinedSignal.addEventListener('abort', () => console.log('Abort!'))
// Abort after 1 second
const timeoutId = setTimeout(() => timeoutController.abort(), 1000)
// The user or the timeout can now abort the action
await performSomeAction({ signal: combinedSignal })
clearTimeout(timeoutId)
// Clear will clean up internal event handlers
combinedSignal.clear()API
anySignal(signals)
Parameters
| Name | Type | Description |
|---|---|---|
| signals | Array<AbortSignal> |
The Signals that will be observed and mapped to the returned Signal |
Returns
| Type | Description |
|---|---|
ClearableSignal |
A Signal that will be aborted as soon as any one of its parent signals are aborted. Extends AbortSignal with the clear function for cleanup |
The returned ClearableSignal will only be aborted once, and as soon as one of its parent signals is aborted.
ClearableSignal.clear()
Removes all internal event handlers. This must be called after abort has been called, or the signals have successfully executed, otherwise there is a risk of leaking event handlers.
Acknowledgements
The anySignal function is taken from a comment by jakearchibald
LICENSE
MIT © Jacob Heun