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 aduh95 committed Apr 3, 2021
1 parent a59b6a1 commit a44392d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,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 @@ -1139,6 +1140,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 a44392d

Please sign in to comment.