@@ -990,7 +990,7 @@ added: v13.10.0 |
990 | 990 | --> |
991 | 991 |
|
992 | 992 | Creates a new instance of `AsyncLocalStorage`. Store is only provided within a |
993 | | -`run` method call. |
| 993 | +`run` or after `enterWith` method call. |
994 | 994 |
|
995 | 995 | ### `asyncLocalStorage.disable()` |
996 | 996 | <!-- YAML |
@@ -999,7 +999,7 @@ added: v13.10.0 |
999 | 999 |
|
1000 | 1000 | This method disables the instance of `AsyncLocalStorage`. All subsequent calls |
1001 | 1001 | to `asyncLocalStorage.getStore()` will return `undefined` until |
1002 | | -`asyncLocalStorage.run()` is called again. |
| 1002 | +`asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again. |
1003 | 1003 |
|
1004 | 1004 | When calling `asyncLocalStorage.disable()`, all current contexts linked to the |
1005 | 1005 | instance will be exited. |
@@ -1021,7 +1021,8 @@ added: v13.10.0 |
1021 | 1021 |
|
1022 | 1022 | This method returns the current store. |
1023 | 1023 | If 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`. |
1025 | 1026 |
|
1026 | 1027 | ### `asyncLocalStorage.enterWith(store)` |
1027 | 1028 | <!-- YAML |
@@ -1030,14 +1031,15 @@ added: v13.11.0 |
1030 | 1031 |
|
1031 | 1032 | * `store` {any} |
1032 | 1033 |
|
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. |
1036 | 1037 |
|
1037 | 1038 | Example: |
1038 | 1039 |
|
1039 | 1040 | ```js |
1040 | 1041 | const store = { id: 1 }; |
| 1042 | +// Replaces previous store with the given store object |
1041 | 1043 | asyncLocalStorage.enterWith(store); |
1042 | 1044 | asyncLocalStorage.getStore(); // Returns the store object |
1043 | 1045 | someAsyncOperation(() => { |
@@ -1048,7 +1050,9 @@ someAsyncOperation(() => { |
1048 | 1050 | This transition will continue for the _entire_ synchronous execution. |
1049 | 1051 | This means that if, for example, the context is entered within an event |
1050 | 1052 | handler 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. |
1052 | 1056 |
|
1053 | 1057 | ```js |
1054 | 1058 | const store = { id: 1 }; |
@@ -1110,14 +1114,15 @@ added: v13.10.0 |
1110 | 1114 |
|
1111 | 1115 | This methods runs a function synchronously outside of a context and return its |
1112 | 1116 | return 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`. |
1114 | 1119 |
|
1115 | 1120 | Optionally, arguments can be passed to the function. They will be passed to |
1116 | 1121 | the callback function. |
1117 | 1122 |
|
1118 | 1123 | If 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. |
1121 | 1126 |
|
1122 | 1127 | Example: |
1123 | 1128 |
|
|