You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
<Metadata version="v19.1.0" data={{"changes":[{"version":["v14.8.0","v12.19.0"],"pr-url":"https://github.com/nodejs/node/pull/34572","description":"Cleanup hooks may now be asynchronous."}]}} />
244
+
<Metadata version="v19.2.0" data={{"changes":[{"version":["v14.8.0","v12.19.0"],"pr-url":"https://github.com/nodejs/node/pull/34572","description":"Cleanup hooks may now be asynchronous."}]}} />
245
245
246
246
In order to be loaded from multiple Node.js environments,
247
247
such as a main thread and a Worker thread, an add-on needs to either:
@@ -440,7 +440,7 @@ illustration of how it can be used.
<Metadata version="v19.1.0" data={{"changes":[{"version":"v16.4.0","pr-url":"https://github.com/nodejs/node/pull/37675","description":"AsyncLocalStorage is now Stable. Previously, it had been Experimental."}],"update":{"type":"added","version":["v13.10.0","v12.17.0"]}}} />
35
+
<Metadata version="v19.2.0" data={{"changes":[{"version":"v16.4.0","pr-url":"https://github.com/nodejs/node/pull/37675","description":"AsyncLocalStorage is now Stable. Previously, it had been Experimental."}],"update":{"type":"added","version":["v13.10.0","v12.17.0"]}}} />
36
36
37
37
This class creates stores that stay coherent through asynchronous operations.
38
38
@@ -113,18 +113,32 @@ Each instance of `AsyncLocalStorage` maintains an independent storage context.
113
113
Multiple instances can safely exist simultaneously without risk of interfering
*`onPropagate`[`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) Optional callback invoked before a store is
124
+
propagated to a new async resource. Returning `true` allows propagation,
125
+
returning `false` avoids it. Default is to propagate always.
119
126
120
127
Creates a new instance of `AsyncLocalStorage`. Store is only provided within a
121
128
`run()` call or after an `enterWith()` call.
122
129
130
+
The `onPropagate` is called during creation of an async resource. Throwing at
131
+
this time will print the stack trace and exit. See
132
+
[`async_hooks` Error handling][] for details.
133
+
134
+
Creating an async resource within the `onPropagate` callback will result in
@@ -305,7 +319,7 @@ probably responsible for the context loss.
305
319
306
320
### <DataTagtag="C" /> `AsyncResource`
307
321
308
-
<Metadata version="v19.1.0" data={{"changes":[{"version":"v16.4.0","pr-url":"https://github.com/nodejs/node/pull/37675","description":"AsyncResource is now Stable. Previously, it had been Experimental."}]}} />
322
+
<Metadata version="v19.2.0" data={{"changes":[{"version":"v16.4.0","pr-url":"https://github.com/nodejs/node/pull/37675","description":"AsyncResource is now Stable. Previously, it had been Experimental."}]}} />
309
323
310
324
The class `AsyncResource` is designed to be extended by the embedder's async
311
325
resources. Using this, users can easily trigger the lifetime events of their
<Metadata version="v19.1.0" data={{"changes":[{"version":["v17.8.0","v16.15.0"],"pr-url":"https://github.com/nodejs/node/pull/42177","description":"Changed the default when `thisArg` is undefined to use `this` from the caller."},{"version":"v16.0.0","pr-url":"https://github.com/nodejs/node/pull/36782","description":"Added optional thisArg."}],"update":{"type":"added","version":["v14.8.0","v12.19.0"]}}} />
426
+
<Metadata version="v19.2.0" data={{"changes":[{"version":["v17.8.0","v16.15.0"],"pr-url":"https://github.com/nodejs/node/pull/42177","description":"Changed the default when `thisArg` is undefined to use `this` from the caller."},{"version":"v16.0.0","pr-url":"https://github.com/nodejs/node/pull/36782","description":"Added optional thisArg."}],"update":{"type":"added","version":["v14.8.0","v12.19.0"]}}} />
413
427
414
428
*`fn`[`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) The function to bind to the current execution context.
415
429
*`type`[`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) An optional name to associate with the underlying
@@ -423,7 +437,7 @@ the `AsyncResource` to which the function is bound.
<Metadata version="v19.1.0" data={{"changes":[{"version":["v17.8.0","v16.15.0"],"pr-url":"https://github.com/nodejs/node/pull/42177","description":"Changed the default when `thisArg` is undefined to use `this` from the caller."},{"version":"v16.0.0","pr-url":"https://github.com/nodejs/node/pull/36782","description":"Added optional thisArg."}],"update":{"type":"added","version":["v14.8.0","v12.19.0"]}}} />
440
+
<Metadata version="v19.2.0" data={{"changes":[{"version":["v17.8.0","v16.15.0"],"pr-url":"https://github.com/nodejs/node/pull/42177","description":"Changed the default when `thisArg` is undefined to use `this` from the caller."},{"version":"v16.0.0","pr-url":"https://github.com/nodejs/node/pull/36782","description":"Added optional thisArg."}],"update":{"type":"added","version":["v14.8.0","v12.19.0"]}}} />
427
441
428
442
*`fn`[`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) The function to bind to the current `AsyncResource`.
*`fn`[`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) The function to call in the execution context of this async
<Metadata version="v19.2.0" data={{"stability":{"level":1,"text":" - Experimental. Please migrate away from this API, if you can. We do not recommend using the `createHook`][], [`AsyncHook`, and\n> `executionAsyncResource` APIs as they have usability issues, safety risks,\n> and performance implications. Async context tracking use cases are better\n> served by the stable `AsyncLocalStorage` API. If you have a use case for\n> `createHook`, `AsyncHook`, or `executionAsyncResource` beyond the context\n> tracking need solved by `AsyncLocalStorage` or diagnostics data currently\n> provided by Diagnostics Channel, please open an issue at\n> <https://github.com/nodejs/node/issues> describing your use case so we can\n> create a more purpose-focused API."}}} />
* Returns: [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) The resource representing the current execution.
613
613
Useful to store data within the resource.
@@ -648,7 +648,7 @@ import { createServer } from 'node:http';
648
648
import {
649
649
executionAsyncId,
650
650
executionAsyncResource,
651
-
createHook
651
+
createHook,
652
652
} from'async_hooks';
653
653
constsym=Symbol('state'); // Private symbol to avoid pollution
<Metadata version="v19.1.0" data={{"changes":[{"version":"v8.2.0","pr-url":"https://github.com/nodejs/node/pull/13490","description":"Renamed from `currentId`."}],"update":{"type":"added","version":["v8.1.0"]}}} />
700
+
<Metadata version="v19.2.0" data={{"changes":[{"version":"v8.2.0","pr-url":"https://github.com/nodejs/node/pull/13490","description":"Renamed from `currentId`."}],"update":{"type":"added","version":["v8.1.0"]}}} />
701
701
702
702
* Returns: [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The `asyncId` of the current execution context. Useful to
703
703
track when something calls.
@@ -764,7 +764,7 @@ the section on [promise execution tracking][].
0 commit comments