From ac5902210619b1792c46f03e747380e294058c5e Mon Sep 17 00:00:00 2001 From: Darkripper214 Date: Thu, 1 Apr 2021 22:06:48 +0800 Subject: [PATCH] doc: fix asyncLocalStorage.run() description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The description that store is not available when asynchronous operation is created within the callback is not accurate Fixes: https://github.com/nodejs/node/issues/38022 PR-URL: https://github.com/nodejs/node/pull/38023 Reviewed-By: Gerhard Stöbich Reviewed-By: Chengzhong Wu --- doc/api/async_hooks.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 8a38458f9fad24..b990ffe34720b4 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -1096,8 +1096,9 @@ added: v13.10.0 * `...args` {any} Runs a function synchronously within a context and returns its -return value. The store is not accessible outside of the callback function or -the asynchronous operations created within the callback. +return value. The store is not accessible outside of the callback function. +The store is accessible to any asynchronous operations created within the +callback. The optional `args` are passed to the callback function. @@ -1111,6 +1112,9 @@ const store = { id: 2 }; try { asyncLocalStorage.run(store, () => { asyncLocalStorage.getStore(); // Returns the store object + setTimeout(() => { + asyncLocalStorage.getStore(); // Returns the store object + }, 200); throw new Error(); }); } catch (e) {