Skip to content

Commit

Permalink
timers: reject with AbortError on cancellation
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
benjamingr authored and targos committed Jun 11, 2021
1 parent 5acf0a5 commit 6799738
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions lib/internal/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,16 @@ const {
} = require('internal/timers');

const {
hideStackFrames,
AbortError,
codes: { ERR_INVALID_ARG_TYPE }
} = require('internal/errors');

const { validateAbortSignal } = require('internal/validators');

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());
}
}

Expand Down Expand Up @@ -61,8 +53,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) => {
Expand Down Expand Up @@ -107,8 +98,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) => {
Expand Down

0 comments on commit 6799738

Please sign in to comment.