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 <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
PhakornKiong authored and targos committed May 1, 2021
1 parent 8590720 commit ac59022
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 @@ -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.

Expand All @@ -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) {
Expand Down

0 comments on commit ac59022

Please sign in to comment.