@@ -1085,6 +1085,21 @@ In this example, the store is only available in the callback function and the |
1085 | 1085 | functions called by `foo`. Outside of `run`, calling `getStore` will return |
1086 | 1086 | `undefined`. |
1087 | 1087 |
|
| 1088 | +### Troubleshooting |
| 1089 | + |
| 1090 | +In most cases your application or library code should have no issues with |
| 1091 | +`AsyncLocalStorage`. But in rare cases you may face situations when the |
| 1092 | +current store is lost in one of asynchronous operations. Then you should |
| 1093 | +consider the following options. |
| 1094 | + |
| 1095 | +If your code is callback-based, it is enough to promisify it with |
| 1096 | +[`util.promisify()`][], so it starts working with native promises. |
| 1097 | + |
| 1098 | +If you need to keep using callback-based API, or your code assumes |
| 1099 | +a custom thenable implementation, you should use [`AsyncResource`][] class |
| 1100 | +to associate the asynchronous operation with the correct execution context. |
| 1101 | + |
| 1102 | +[`AsyncResource`]: #async_hooks_class_asyncresource |
1088 | 1103 | [`after` callback]: #async_hooks_after_asyncid |
1089 | 1104 | [`before` callback]: #async_hooks_before_asyncid |
1090 | 1105 | [`destroy` callback]: #async_hooks_destroy_asyncid |
@@ -1094,3 +1109,4 @@ functions called by `foo`. Outside of `run`, calling `getStore` will return |
1094 | 1109 | [PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk/edit |
1095 | 1110 | [`Worker`]: worker_threads.html#worker_threads_class_worker |
1096 | 1111 | [promise execution tracking]: #async_hooks_promise_execution_tracking |
| 1112 | +[`util.promisify()`]: util.html#util_util_promisify_original |