Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
doc: simplify addAbortListener example
The example was written before v8 supported the using keyword
and hence explicitly called Symbol.dispose

Since now the keyword is supported, the example can be simplified
  • Loading branch information
atlowChemi committed Feb 15, 2026
commit b6097b8bb25ed3362d0b8898172dcf9e1066b5fe
26 changes: 8 additions & 18 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1908,31 +1908,21 @@ Returns a disposable so that it may be unsubscribed from more easily.
const { addAbortListener } = require('node:events');

function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
using _ = addAbortListener(signal, (e) => {
Comment thread
atlowChemi marked this conversation as resolved.
// Do something when signal is aborted.
});
Comment thread
Renegade334 marked this conversation as resolved.
}
```

```mjs
import { addAbortListener } from 'node:events';

function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
using _ = addAbortListener(signal, (e) => {
Comment thread
atlowChemi marked this conversation as resolved.
// Do something when signal is aborted.
});
}
```

Expand Down
Loading