@@ -990,7 +990,7 @@ added: v13.10.0
990990-->
991991
992992Creates a new instance of ` AsyncLocalStorage ` . Store is only provided within a
993- ` run ` method call.
993+ ` run ` or after ` enterWith ` method call.
994994
995995### ` asyncLocalStorage.disable() `
996996<!-- YAML
@@ -999,7 +999,7 @@ added: v13.10.0
999999
10001000This method disables the instance of ` AsyncLocalStorage ` . All subsequent calls
10011001to ` asyncLocalStorage.getStore() ` will return ` undefined ` until
1002- ` asyncLocalStorage.run() ` is called again.
1002+ ` asyncLocalStorage.run() ` or ` asyncLocalStorage.enterWith() ` is called again.
10031003
10041004When calling ` asyncLocalStorage.disable() ` , all current contexts linked to the
10051005instance will be exited.
@@ -1021,7 +1021,8 @@ added: v13.10.0
10211021
10221022This method returns the current store.
10231023If this method is called outside of an asynchronous context initialized by
1024- calling ` asyncLocalStorage.run ` , it will return ` undefined ` .
1024+ calling ` asyncLocalStorage.run() ` or ` asyncLocalStorage.enterWith() ` , it will
1025+ return ` undefined ` .
10251026
10261027### ` asyncLocalStorage.enterWith(store) `
10271028<!-- YAML
@@ -1030,14 +1031,15 @@ added: v13.11.0
10301031
10311032* ` store ` {any}
10321033
1033- Calling ` asyncLocalStorage.enterWith(store) ` will transition into the context
1034- for the remainder of the current synchronous execution and will persist
1035- through any following asynchronous calls.
1034+ This method transitions into the context for the remainder of the current
1035+ synchronous execution and then persists the store through any following
1036+ asynchronous calls.
10361037
10371038Example:
10381039
10391040``` js
10401041const store = { id: 1 };
1042+ // Replaces previous store with the given store object
10411043asyncLocalStorage .enterWith (store);
10421044asyncLocalStorage .getStore (); // Returns the store object
10431045someAsyncOperation (() => {
@@ -1048,7 +1050,9 @@ someAsyncOperation(() => {
10481050This transition will continue for the _ entire_ synchronous execution.
10491051This means that if, for example, the context is entered within an event
10501052handler subsequent event handlers will also run within that context unless
1051- specifically bound to another context with an ` AsyncResource ` .
1053+ specifically bound to another context with an ` AsyncResource ` . That is why
1054+ ` run ` should be preferred over ` enterWith ` unless there are strong reasons
1055+ to use the latter method.
10521056
10531057``` js
10541058const store = { id: 1 };
@@ -1110,14 +1114,15 @@ added: v13.10.0
11101114
11111115This methods runs a function synchronously outside of a context and return its
11121116return value. The store is not accessible within the callback function or
1113- the asynchronous operations created within the callback.
1117+ the asynchronous operations created within the callback, i.e. any ` getStore `
1118+ call done within the callback function will always return ` undefined ` .
11141119
11151120Optionally, arguments can be passed to the function. They will be passed to
11161121the callback function.
11171122
11181123If the callback function throws an error, it will be thrown by ` exit ` too.
1119- The stacktrace will not be impacted by this call and
1120- the context will be re-entered.
1124+ The stacktrace will not be impacted by this call and the context will be
1125+ re-entered.
11211126
11221127Example:
11231128
0 commit comments