@jsenv/abort
Advanced tools
Comparing version 4.1.0 to 4.1.1
{ | ||
"name": "@jsenv/abort", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Help to write code compatible with abort signals", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -99,6 +99,14 @@ /* | ||
const addAbortSignal = (signal, cancel = cancelNoop) => { | ||
const addAbortSignal = ( | ||
signal, | ||
{ onAbort = callbackNoop, onRemove = callbackNoop } = {}, | ||
) => { | ||
const callback = (fn) => { | ||
onAbort = onRemove = callbackNoop | ||
fn() | ||
} | ||
if (operationSignal.aborted) { | ||
cancel() | ||
return cancel | ||
callback(onAbort) | ||
return callbackNoop | ||
} | ||
@@ -108,3 +116,4 @@ | ||
operationAbortController.abort() | ||
return cancel | ||
callback(onAbort) | ||
return callbackNoop | ||
} | ||
@@ -134,3 +143,3 @@ | ||
operation_abort: () => { | ||
cancel() | ||
callback(onAbort) | ||
}, | ||
@@ -142,5 +151,6 @@ operation_end: () => { | ||
// - call any custom cancel function | ||
cancel() | ||
callback(onRemove) | ||
}, | ||
child_abort: () => { | ||
callback(onAbort) | ||
operationAbortController.abort() | ||
@@ -155,3 +165,3 @@ }, | ||
cancelRace() | ||
cancel() | ||
callback(onRemove) | ||
} | ||
@@ -167,3 +177,3 @@ } | ||
signal: abortSourceSignal, | ||
remove: cancelNoop, | ||
remove: callbackNoop, | ||
} | ||
@@ -175,6 +185,10 @@ } | ||
}) | ||
const cancelEffect = | ||
typeof returnValue === "function" ? returnValue : cancelNoop | ||
const removeAbortSource = | ||
typeof returnValue === "function" ? returnValue : callbackNoop | ||
const removeAbortSignal = addAbortSignal(abortSourceSignal, cancelEffect) | ||
const removeAbortSignal = addAbortSignal(abortSourceSignal, { | ||
onRemove: () => { | ||
removeAbortSource() | ||
}, | ||
}) | ||
return { | ||
@@ -201,3 +215,7 @@ signal: abortSourceSignal, | ||
const signal = abortController.signal | ||
const removeAbortSignal = addAbortSignal(signal) | ||
const removeAbortSignal = addAbortSignal(signal, { | ||
onAbort: () => { | ||
abortController.abort() | ||
}, | ||
}) | ||
try { | ||
@@ -216,3 +234,7 @@ const value = await asyncCallback(signal) | ||
const signal = abortController.signal | ||
const removeAbortSignal = addAbortSignal(signal) | ||
const removeAbortSignal = addAbortSignal(signal, { | ||
onAbort: () => { | ||
abortController.abort() | ||
}, | ||
}) | ||
try { | ||
@@ -247,3 +269,3 @@ const value = callback(signal) | ||
const cancelNoop = () => {} | ||
const callbackNoop = () => {} | ||
@@ -250,0 +272,0 @@ const addEventListener = (target, eventName, cb) => { |
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
20935
478