From cf4fa79f1778eb3d8b3a529be751536db65d2ded 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 Backport-PR-URL: https://github.com/nodejs/node/pull/38386 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 da86cada230092..e92dd5fc47d732 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -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`