Skip to content

Commit

Permalink
events: propagate abortsignal reason in new AbortError constructor in…
Browse files Browse the repository at this point in the history
… events

Signed-off-by: James M Snell <jasnell@gmail.com>
  • Loading branch information
jasnell committed Nov 29, 2021
1 parent df77f2f commit 5edb1d1
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 @@ -810,7 +810,7 @@ async function once(emitter, name, options = {}) {
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 @@ -835,7 +835,7 @@ async function once(emitter, name, options = {}) {
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 @@ -888,7 +888,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 @@ -976,7 +976,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 5edb1d1

Please sign in to comment.