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

PR-URL: #40381
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
elegantcoder authored and targos committed Oct 13, 2021
1 parent 93cecb4 commit 6f77d1a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions doc/api/async_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,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 @@ -238,6 +239,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 6f77d1a

Please sign in to comment.