Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timers: reject with AbortError on cancellation #36317

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 4 additions & 14 deletions lib/timers/promises.js
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