@jsenv/abort
Advanced tools
Comparing version 4.2.3 to 4.2.4
{ | ||
"name": "@jsenv/abort", | ||
"version": "4.2.3", | ||
"version": "4.2.4", | ||
"description": "Help to write code compatible with abort signals", | ||
@@ -12,4 +12,3 @@ "license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
"access": "public" | ||
}, | ||
@@ -38,2 +37,2 @@ "author": { | ||
"dependencies": {} | ||
} | ||
} |
@@ -10,3 +10,3 @@ /* | ||
isAbortError: (error) => { | ||
return error.name === "AbortError" | ||
return error && error.name === "AbortError" | ||
}, | ||
@@ -177,27 +177,26 @@ | ||
const addAbortSource = (abortSourceCallback) => { | ||
const abortSource = { | ||
cleaned: false, | ||
signal: null, | ||
remove: callbackNoop, | ||
} | ||
const abortSourceController = new AbortController() | ||
const abortSourceSignal = abortSourceController.signal | ||
abortSource.signal = abortSourceSignal | ||
if (operationSignal.aborted) { | ||
return { | ||
signal: abortSourceSignal, | ||
remove: callbackNoop, | ||
} | ||
return abortSource | ||
} | ||
const returnValue = abortSourceCallback((value) => { | ||
abortSourceController.abort(value) | ||
}) | ||
const removeAbortSource = | ||
typeof returnValue === "function" ? returnValue : callbackNoop | ||
const removeAbortSignal = addAbortSignal(abortSourceSignal, { | ||
onRemove: () => { | ||
removeAbortSource() | ||
if (typeof returnValue === "function") { | ||
returnValue() | ||
} | ||
abortSource.cleaned = true | ||
}, | ||
}) | ||
return { | ||
signal: abortSourceSignal, | ||
remove: removeAbortSignal, | ||
} | ||
abortSource.remove = removeAbortSignal | ||
return abortSource | ||
} | ||
@@ -204,0 +203,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
18362
486