From 1022d3d947126f75cedfddd02a7cd382e52c9c02 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 11 Mar 2021 07:24:03 -0800 Subject: [PATCH] doc: recommend checking abortSignal.aborted first Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/37714 Reviewed-By: Antoine du Hamel Reviewed-By: Trivikram Kamat Reviewed-By: Darshan Sen Reviewed-By: Rich Trott --- doc/api/globals.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index 6144c662a22821..be3c6d6ad9a439 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -91,11 +91,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`