Skip to content

Commit 2db491c

Browse files
committed
fixup! doc: simplify addAbortListener example
1 parent b6097b8 commit 2db491c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

doc/api/events.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,8 @@ const { addAbortListener } = require('node:events');
19091909

19101910
function example(signal) {
19111911
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
1912+
// addAbortListener() returns a disposable, so the `using` keyword ensures
1913+
// the abort listener is automatically removed when this scope exits.
19121914
using _ = addAbortListener(signal, (e) => {
19131915
// Do something when signal is aborted.
19141916
});
@@ -1920,6 +1922,8 @@ import { addAbortListener } from 'node:events';
19201922

19211923
function example(signal) {
19221924
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
1925+
// addAbortListener() returns a disposable, so the `using` keyword ensures
1926+
// the abort listener is automatically removed when this scope exits.
19231927
using _ = addAbortListener(signal, (e) => {
19241928
// Do something when signal is aborted.
19251929
});

0 commit comments

Comments
 (0)