mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
doc: recommend checking abortSignal.aborted first
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/37714 Backport-PR-URL: https://github.com/nodejs/node/pull/38386 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
026941381b
commit
cf4fa79f17
1 file changed
+9
-5
+9
-5
@@ -89,11 +89,15 @@ ac.abort();
|
||||
```
|
||||
|
||||
The `AbortController` with which the `AbortSignal` is associated will only
|
||||
ever trigger the `'abort'` event once. Any event listeners attached to the
|
||||
`AbortSignal` *should* use the `{ once: true }` option (or, if using the
|
||||
`EventEmitter` APIs to attach a listener, use the `once()` method) to ensure
|
||||
that the event listener is removed as soon as the `'abort'` event is handled.
|
||||
Failure to do so may result in memory leaks.
|
||||
ever trigger the `'abort'` event once. We recommended that code check
|
||||
that the `abortSignal.aborted` attribute is `false` before adding an `'abort'`
|
||||
event listener.
|
||||
|
||||
Any event listeners attached to the `AbortSignal` should use the
|
||||
`{ once: true }` option (or, if using the `EventEmitter` APIs to attach a
|
||||
listener, use the `once()` method) to ensure that the event listener is
|
||||
removed as soon as the `'abort'` event is handled. Failure to do so may
|
||||
result in memory leaks.
|
||||
|
||||
#### `abortSignal.aborted`
|
||||
<!-- YAML
|
||||
|
||||
Reference in new issue
Block a user