Skip to content

Commit

Permalink
add abort listener using addAbortListener util and invoke disposabl…
Browse files Browse the repository at this point in the history
…e interface
  • Loading branch information
nbbeeken committed Mar 14, 2024
1 parent 95b6c27 commit 5819b36
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,14 +1167,8 @@ function on(emitter, event, options = kEmptyObject) {
addEventListener(emitter, closeEvents[i], closeHandler);
}
}
if (signal) {
kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation;
addEventListener(
signal,
'abort',
abortListener,
{ __proto__: null, once: true, [kResistStopPropagation]: true });
}

const abortListenerDisposable = signal ? addAbortListener(signal, abortListener) : null;

return iterator;

Expand All @@ -1201,6 +1195,7 @@ function on(emitter, event, options = kEmptyObject) {
}

function closeHandler() {
abortListenerDisposable?.[SymbolDispose]();
removeAll();
finished = true;
const doneResult = createIterResult(undefined, true);
Expand Down

0 comments on commit 5819b36

Please sign in to comment.