Skip to content

Commit

Permalink
doc: fix asyncLocalStorage.run() description
Browse files Browse the repository at this point in the history
The description that store is not available
when asynchronous operation is created within
the callback is not accurate

Fixes: #38022

PR-URL: #38023
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
PhakornKiong authored and MylesBorins committed Apr 4, 2021
1 parent 2a36867 commit d8e2d46
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions doc/api/async_hooks.md
Expand Up @@ -1114,8 +1114,9 @@ added:
* `...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.

Expand All @@ -1129,6 +1130,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) {
Expand Down

0 comments on commit d8e2d46

Please sign in to comment.