mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
timers: reject with AbortError on cancellation
PR-URL: https://github.com/nodejs/node/pull/36317 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
parent
780fcb4249
commit
1ed72f67f5
@ -14,22 +14,14 @@ const {
|
||||
} = require('internal/timers');
|
||||
|
||||
const {
|
||||
hideStackFrames,
|
||||
AbortError,
|
||||
codes: { ERR_INVALID_ARG_TYPE }
|
||||
} = require('internal/errors');
|
||||
|
||||
let DOMException;
|
||||
|
||||
const lazyDOMException = hideStackFrames((message, name) => {
|
||||
if (DOMException === undefined)
|
||||
DOMException = internalBinding('messaging').DOMException;
|
||||
return new DOMException(message, name);
|
||||
});
|
||||
|
||||
function cancelListenerHandler(clear, reject) {
|
||||
if (!this._destroyed) {
|
||||
clear(this);
|
||||
reject(lazyDOMException('The operation was aborted', 'AbortError'));
|
||||
reject(new AbortError());
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +56,7 @@ function setTimeout(after, value, options = {}) {
|
||||
// to 12.x, then this can be converted to use optional chaining to
|
||||
// simplify the check.
|
||||
if (signal && signal.aborted) {
|
||||
return PromiseReject(
|
||||
lazyDOMException('The operation was aborted', 'AbortError'));
|
||||
return PromiseReject(new AbortError());
|
||||
}
|
||||
let oncancel;
|
||||
const ret = new Promise((resolve, reject) => {
|
||||
@ -115,8 +106,7 @@ function setImmediate(value, options = {}) {
|
||||
// to 12.x, then this can be converted to use optional chaining to
|
||||
// simplify the check.
|
||||
if (signal && signal.aborted) {
|
||||
return PromiseReject(
|
||||
lazyDOMException('The operation was aborted', 'AbortError'));
|
||||
return PromiseReject(new AbortError());
|
||||
}
|
||||
let oncancel;
|
||||
const ret = new Promise((resolve, reject) => {
|
||||
|
Loading…
Reference in New Issue
Block a user