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 danielleadams committed Dec 7, 2020
1 parent 4127eb2 commit 29b5236
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions lib/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 29b5236

Please sign in to comment.