Skip to content

doc: simplify addAbortListener example#61842

Open
atlowChemi wants to merge 2 commits intonodejs:mainfrom
atlowChemi:use-the-using-keyword
Open

doc: simplify addAbortListener example#61842
atlowChemi wants to merge 2 commits intonodejs:mainfrom
atlowChemi:use-the-using-keyword

Conversation

@atlowChemi
Copy link
Member

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.

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. events Issues and PRs related to the events subsystem / EventEmitter. labels Feb 15, 2026
@atlowChemi atlowChemi force-pushed the use-the-using-keyword branch from a82b1f5 to 83dbc3e Compare February 15, 2026 21:31
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
@atlowChemi atlowChemi force-pushed the use-the-using-keyword branch from 83dbc3e to b6097b8 Compare February 15, 2026 21:37
@Renegade334 Renegade334 added dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. labels Feb 15, 2026
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
// addAbortListener() returns a disposable, so the `using` keyword ensures
// the abort listener is automatically removed when this scope exits.
using _ = addAbortListener(signal, (e) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using _ = addAbortListener(signal, (e) => {
using listener = addAbortListener(signal, (e) => {

Copy link
Member Author

@atlowChemi atlowChemi Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns an object which only has a disposer, so it really has no use other than the disposal: (so I think giving it a name might be confusing)

return {
__proto__: null,
[SymbolDispose]() {
removeEventListener?.();
},
};

signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
// addAbortListener() returns a disposable, so the `using` keyword ensures
// the abort listener is automatically removed when this scope exits.
using _ = addAbortListener(signal, (e) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using _ = addAbortListener(signal, (e) => {
using listener = addAbortListener(signal, (e) => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. events Issues and PRs related to the events subsystem / EventEmitter.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants