Skip to content

Commit cf4fa79

Browse files
jasnelltargos
authored andcommitted
doc: recommend checking abortSignal.aborted first
Signed-off-by: James M Snell <[email protected]> PR-URL: #37714 Backport-PR-URL: #38386 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 0269413 commit cf4fa79

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
@@ -89,11 +89,15 @@ ac.abort();
8989
```
9090

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

98102
#### `abortSignal.aborted`
99103
<!-- YAML

0 commit comments

Comments
 (0)