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
  • Loading branch information
PhakornKiong committed Apr 1, 2021
1 parent 3ef9562 commit 50d1bfc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,8 @@ 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 accesible to any asynchronous operations created within the callback.

The optional `args` are passed to the callback function.

Expand All @@ -1139,6 +1139,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 50d1bfc

Please sign in to comment.