any-signal
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -1,5 +0,9 @@ | ||
declare function anySignal(signals: AbortSignal[]): AbortSignal; | ||
interface ClearableSignal extends AbortSignal { | ||
clear(): void | ||
} | ||
export {anySignal}; | ||
declare function anySignal(signals: Array<AbortSignal | undefined | null>): ClearableSignal; | ||
export {anySignal, type ClearableSignal}; | ||
export default anySignal; |
18
index.js
@@ -5,3 +5,3 @@ /** | ||
* @param {Array<AbortSignal>} signals | ||
* @returns {AbortSignal} | ||
* @returns {ClearableSignal} | ||
*/ | ||
@@ -29,3 +29,17 @@ function anySignal (signals) { | ||
return controller.signal | ||
function clear () { | ||
for (const signal of signals) { | ||
if (!signal || !signal.removeEventListener) continue | ||
signal.removeEventListener('abort', onAbort) | ||
} | ||
} | ||
return new Proxy(controller.signal, { | ||
get (target, p) { | ||
if (p === 'clear') { | ||
return clear | ||
} | ||
return target[p] | ||
} | ||
}) | ||
} | ||
@@ -32,0 +46,0 @@ |
{ | ||
"name": "any-signal", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "Combines an array of AbortSignals into a single signal that is aborted when any signal is", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# any-signal | ||
[![Build Status](https://travis-ci.org/jacobheun/any-signal.svg?branch=master)](https://travis-ci.org/jacobheun/any-signal) [![dependencies Status](https://david-dm.org/jacobheun/any-signal/status.svg)](https://david-dm.org/jacobheun/any-signal) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
[![Build Status](https://github.com/jacobheun/any-signal/actions/workflows/node.js.yml/badge.svg?branch=master)](https://travis-ci.org/jacobheun/any-signal) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
@@ -30,2 +30,5 @@ > Combines an array of AbortSignals into a single signal that is aborted when any signal is. | ||
clearTimeout(timeoutId) | ||
// Clear will clean up internal event handlers | ||
combinedSignal.clear() | ||
``` | ||
@@ -47,6 +50,9 @@ | ||
|------|-------------| | ||
| [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | A Signal that will be aborted as soon as any one of its parent signals are aborted. | | ||
| `ClearableSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | 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 [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) will only be aborted once, and as soon as one of its parent signals is aborted. | ||
The returned [`ClearableSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) 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 | ||
@@ -53,0 +59,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5460
46
63