Skip to content

Commit

Permalink
events: propagate abortsignal reason in new AbortError ctor in events
Browse files Browse the repository at this point in the history
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #41008
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
jasnell authored and targos committed Aug 1, 2022
1 parent 36dd39d commit 979c98a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ async function once(emitter, name, options = kEmptyObject) {
const signal = options?.signal;
validateAbortSignal(signal, 'options.signal');
if (signal?.aborted)
throw new AbortError();
throw new AbortError(undefined, { cause: signal?.reason });
return new Promise((resolve, reject) => {
const errorListener = (err) => {
emitter.removeListener(name, resolver);
Expand All @@ -955,7 +955,7 @@ async function once(emitter, name, options = kEmptyObject) {
function abortListener() {
eventTargetAgnosticRemoveListener(emitter, name, resolver);
eventTargetAgnosticRemoveListener(emitter, 'error', errorListener);
reject(new AbortError());
reject(new AbortError(undefined, { cause: signal?.reason }));
}
if (signal != null) {
eventTargetAgnosticAddListener(
Expand Down Expand Up @@ -1006,7 +1006,7 @@ function on(emitter, event, options) {
const signal = options?.signal;
validateAbortSignal(signal, 'options.signal');
if (signal?.aborted)
throw new AbortError();
throw new AbortError(undefined, { cause: signal?.reason });

const unconsumedEvents = [];
const unconsumedPromises = [];
Expand Down Expand Up @@ -1094,7 +1094,7 @@ function on(emitter, event, options) {
return iterator;

function abortListener() {
errorHandler(new AbortError());
errorHandler(new AbortError(undefined, { cause: signal?.reason }));
}

function eventHandler(...args) {
Expand Down

0 comments on commit 979c98a

Please sign in to comment.