abort-utils
Version:
Utility functions to use and combine `AbortSignal` and `AbortController` with Promises
19 lines (18 loc) • 410 B
JavaScript
export function abortAll(iterable) {
for (const controller of iterable) {
controller.abort();
}
}
/**
* Aborts all controllers in an Array/Set and empties it.
* @param list - The Array/Set of controllers to abort and clear.
*/
export function abortAllAndClear(list) {
abortAll(list);
if (Array.isArray(list)) {
list.length = 0;
}
else {
list.clear();
}
}