From f8264402a3a6a4435e8ef949bcfa6ef2fb85c3e0 Mon Sep 17 00:00:00 2001 From: Rawal27 Date: Tue, 11 Aug 2026 10:16:05 +0530 Subject: [PATCH 1/2] doc: improve AsyncResource scope wording Signed-off-by: Rawal27 --- doc/api/async_context.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/api/async_context.md b/doc/api/async_context.md index 372bf9231e86..e31d1ea554f5 100644 --- a/doc/api/async_context.md +++ b/doc/api/async_context.md @@ -11,7 +11,7 @@ These classes are used to associate state and propagate it throughout callbacks and promise chains. They allow storing data throughout the lifetime of a web request -or any other asynchronous duration. It is similar to thread-local storage +or any other asynchronous operation. It is similar to thread-local storage in other languages. The `AsyncLocalStorage` and `AsyncResource` classes are part of the @@ -142,7 +142,7 @@ changes: * `defaultValue` {any} The default value to be used when no store is provided. * `name` {string} A name for the `AsyncLocalStorage` value. -Creates a new instance of `AsyncLocalStorage`. Store is only provided within a +Creates a new instance of `AsyncLocalStorage`. A Store is only provided within a `run()` call or after an `enterWith()` call. ### Static method: `AsyncLocalStorage.bind(fn)` @@ -222,11 +222,11 @@ to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again. When calling `asyncLocalStorage.disable()`, all current contexts linked to the -instance will be exited. +instance are exited. Calling `asyncLocalStorage.disable()` is required before the `asyncLocalStorage` can be garbage collected. This does not apply to stores -provided by the `asyncLocalStorage`, as those objects are garbage collected +provided by the `asyncLocalStorage` instance, as those objects are garbage collected along with the corresponding async resources. Use this method when the `asyncLocalStorage` is not in use anymore @@ -750,7 +750,7 @@ changes: * `fn` {Function} The function to bind to the current `AsyncResource`. * `thisArg` {any} -Binds the given function to execute to this `AsyncResource`'s scope. +Binds the given function to execute within this `AsyncResource`'s scope. ### `asyncResource.runInAsyncScope(fn[, thisArg, ...args])` @@ -773,8 +773,8 @@ then restore the original execution context. * Returns: {AsyncResource} A reference to `asyncResource`. Call all `destroy` hooks. This should only ever be called once. An error will -be thrown if it is called more than once. This **must** be manually called. If -the resource is left to be collected by the GC then the `destroy` hooks will +be thrown if it is called more than once. This method **must** be called manually. If +the resource is left to be collected by the GC, then the `destroy` hooks will never be called. ### `asyncResource.asyncId()` @@ -811,7 +811,7 @@ parentPort.on('message', (task) => { }); ``` -a Worker pool around it could use the following structure: +a worker pool around it could use the following structure: ```mjs import { AsyncResource } from 'node:async_hooks'; From a7c0e2087559301e6be7612f96a7b7038e0362dc Mon Sep 17 00:00:00 2001 From: Rawal27 Date: Tue, 11 Aug 2026 12:24:39 +0530 Subject: [PATCH 2/2] Store Typo Signed-off-by: Rawal27 --- doc/api/async_context.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/async_context.md b/doc/api/async_context.md index e31d1ea554f5..1f88479196d0 100644 --- a/doc/api/async_context.md +++ b/doc/api/async_context.md @@ -142,7 +142,7 @@ changes: * `defaultValue` {any} The default value to be used when no store is provided. * `name` {string} A name for the `AsyncLocalStorage` value. -Creates a new instance of `AsyncLocalStorage`. A Store is only provided within a +Creates a new instance of `AsyncLocalStorage`. A store is only provided within a `run()` call or after an `enterWith()` call. ### Static method: `AsyncLocalStorage.bind(fn)`