Skip to content

Commit 0563260

Browse files
jasnelldanielleadams
authored andcommitted
doc: recommend checking abortSignal.aborted first
Signed-off-by: James M Snell <[email protected]> PR-URL: #37714 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 8c084d9 commit 0563260

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

doc/api/globals.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ ac.abort();
9191
```
9292

9393
The `AbortController` with which the `AbortSignal` is associated will only
94-
ever trigger the `'abort'` event once. Any event listeners attached to the
95-
`AbortSignal` *should* use the `{ once: true }` option (or, if using the
96-
`EventEmitter` APIs to attach a listener, use the `once()` method) to ensure
97-
that the event listener is removed as soon as the `'abort'` event is handled.
98-
Failure to do so may result in memory leaks.
94+
ever trigger the `'abort'` event once. We recommended that code check
95+
that the `abortSignal.aborted` attribute is `false` before adding an `'abort'`
96+
event listener.
97+
98+
Any event listeners attached to the `AbortSignal` should use the
99+
`{ once: true }` option (or, if using the `EventEmitter` APIs to attach a
100+
listener, use the `once()` method) to ensure that the event listener is
101+
removed as soon as the `'abort'` event is handled. Failure to do so may
102+
result in memory leaks.
99103

100104
#### `abortSignal.aborted`
101105
<!-- YAML

0 commit comments

Comments
 (0)