chunk_id
large_stringlengths
36
36
doc_type
large_stringclasses
2 values
category
large_stringclasses
17 values
document
large_stringclasses
50 values
version_raw
large_stringclasses
590 values
chunk_index
int64
0
262
text
large_stringlengths
11
5.69k
file_path
large_stringclasses
882 values
f12e6883-e862-55dd-9214-684ddedc4d67
docs
nodejs
nodejs_async_hooks
10x
19
init for PROMISE with id 6, trigger id: 5 # the Promise returned by then() before 6 # the then() callback is entered promise resolve 6 # the then() callback resolves the promise by returning after 6 ``` #### async\_hooks.executionAsyncId()[#](#async_hooks_async_hooks_executionasyncid) Histor...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
e672f5e3-fb72-5e91-8a41-4583f64d4a2b
docs
nodejs
nodejs_async_hooks
10x
20
const server = net.createServer((conn) => { // Returns the ID of the server, not of the new connection, because the // callback runs in the execution scope of the server's MakeCallback(). async_hooks.executionAsyncId(); }).listen(port, () => { // Returns the ID of a TickObject (i.e. process.nextTick()) because...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
8295c22d-4598-593e-9805-dce96fadf8d6
docs
nodejs
nodejs_async_hooks
10x
21
// was that of the new connection. Thus the return value of triggerAsyncId() // is the asyncId of "conn". async_hooks.triggerAsyncId(); }).listen(port, () => { // Even though all callbacks passed to .listen() are wrapped in a nextTick() // the callback itself exists because the call to the server's .listen()...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
9b85201b-778b-5b40-844c-384c83ae7c22
docs
nodejs
nodejs_async_hooks
10x
22
correct execution and trigger ids for promise callback contexts by default. ```None const ah = require('async_hooks'); Promise.resolve(1729).then(() => { console.log(`eid ${ah.executionAsyncId()} tid ${ah.triggerAsyncId()}`); }); // produces: // eid 1 tid 0 ``` Observe that the `then()` callback claims to have exec...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
c26e6da8-4ac4-593d-9cbb-262082f09220
docs
nodejs
nodejs_async_hooks
10x
23
promises. There are two promises in the example above; the promise created by `Promise.resolve()` and the promise returned by the call to `then()`. In the example above, the first promise got the `asyncId` `6` and the latter got `asyncId` `7`. During the execution of the `then()` callback, we are executing in the conte...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
16a4799a-ec74-5691-91f1-cfabe0650458
docs
nodejs
nodejs_async_hooks
10x
24
`AsyncWrap` JavaScript API so that all the appropriate callbacks are called. ### Class: AsyncResource[[src]](https://github.com/nodejs/node/blob/5182a7ece0b71feeb9157f7aa348a15d53e32058/lib/async_hooks.js#L141)[#](#async_hooks_class_asyncresource) The class `AsyncResource` is designed to be extended by the embedder's...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
0d6cb5ec-cf20-50a9-b162-6b297063988f
docs
nodejs
nodejs_async_hooks
10x
25
// * establish the context of the resource // * trigger the AsyncHooks before callbacks // * call the provided function `fn` with the supplied arguments // * trigger the AsyncHooks after callbacks // * restore the original execution context asyncResource.runInAsyncScope(fn, thisArg, ...args); // Call AsyncHooks destro...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
e694f2e1-6f4e-5b70-865a-1b07880f809f
docs
nodejs
nodejs_async_hooks
10x
26
+ `triggerAsyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The ID of the execution context that created this async event. **Default:** `executionAsyncId()`. + `requireManualDestroy` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
459634b6-b32f-5fed-b39e-09b90b6a5676
docs
nodejs
nodejs_async_hooks
10x
27
#### asyncResource.runInAsyncScope(fn[, thisArg, ...args])[[src]](https://github.com/nodejs/node/blob/5182a7ece0b71feeb9157f7aa348a15d53e32058/lib/async_hooks.js#L184)[#](#async_hooks_asyncresource_runinasyncscope_fn_thisarg_args) Added in: v9.6.0 * `fn` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaS...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
7ad4fe6f-7927-5eb9-ae60-1eb6824d5869
docs
nodejs
nodejs_async_hooks
10x
28
#### asyncResource.emitBefore()[[src]](https://github.com/nodejs/node/blob/5182a7ece0b71feeb9157f7aa348a15d53e32058/lib/async_hooks.js#L172)[#](#async_hooks_asyncresource_emitbefore) Deprecated since: v9.6.0 [Stability: 0](documentation.html#documentation_stability_index) - Deprecated: Use [`asyncResource.runInAsyncS...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
f7cf61bb-f3f9-5ddb-9bec-faea1d4ef40a
docs
nodejs
nodejs_async_hooks
10x
29
#### asyncResource.emitAfter()[[src]](https://github.com/nodejs/node/blob/5182a7ece0b71feeb9157f7aa348a15d53e32058/lib/async_hooks.js#L178)[#](#async_hooks_asyncresource_emitafter) Deprecated since: v9.6.0 [Stability: 0](documentation.html#documentation_stability_index) - Deprecated: Use [`asyncResource.runInAsyncSco...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
85011b06-3664-583c-835b-fb712e7316f3
docs
nodejs
nodejs_async_hooks
10x
30
considered deprecated. Please use `runInAsyncScope`, as it provides a much safer alternative. #### asyncResource.emitDestroy()[[src]](https://github.com/nodejs/node/blob/5182a7ece0b71feeb9157f7aa348a15d53e32058/lib/async_hooks.js#L195)[#](#async_hooks_asyncresource_emitdestroy) * Returns: [<AsyncResource>](async_hook...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
e4657677-c8fb-548c-9274-3a316ecac2eb
docs
nodejs
nodejs_async_hooks
10x
31
#### asyncResource.triggerAsyncId()[[src]](https://github.com/nodejs/node/blob/5182a7ece0b71feeb9157f7aa348a15d53e32058/lib/async_hooks.js#L205)[#](#async_hooks_asyncresource_triggerasyncid) * Returns: [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The same `triggerAsyn...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_10x.md
c49d8435-33ed-5b2d-b167-f483e3c1e703
docs
nodejs
nodejs_async_hooks
11x
0
# Async Hooks# Source: https://nodejs.org/docs/latest-v11.x/api/async_hooks.html Version: 11.x [Stability: 1](documentation.html#documentation_stability_index) - Experimental The `async_hooks` module provides an API to register callbacks tracking the lifetime of asynchronous resources created inside a Node.js applic...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
85e0b20d-3531-5d3b-8b00-d89a8c30f800
docs
nodejs
nodejs_async_hooks
11x
1
interface, and each thread will use a new set of async IDs. ## Public API[#](#async_hooks_public_api) ### Overview[#](#async_hooks_overview) Following is a simple overview of the public API. ```None const async_hooks = require('async_hooks'); // Return the ID of the current execution context. const eid = async_hoo...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
b779cb5c-8765-587a-aa23-d2eedb194e73
docs
nodejs
nodejs_async_hooks
11x
2
// init is called during object construction. The resource may not have // completed construction when this callback runs, therefore all fields of the // resource referenced by "asyncId" may not have been populated. function init(asyncId, type, triggerAsyncId, resource) { } // Before is called just before the resource...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
b4bd2edc-d430-5e52-873a-ba232c30b53e
docs
nodejs
nodejs_async_hooks
11x
3
#### async\_hooks.createHook(callbacks)[[src]](https://github.com/nodejs/node/blob/v11.15.0^0/lib/async_hooks.js#L121)[#](#async_hooks_async_hooks_createhook_callbacks) Added in: v8.1.0 * `callbacks` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) The [Hook Callback...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
3e6babf0-dc39-5c04-807c-11cef557326d
docs
nodejs
nodejs_async_hooks
11x
4
+ `destroy` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) The [`destroy` callback](#async_hooks_destroy_asyncid). * Returns: [<AsyncHook>](async_hooks.html#async_hooks_async_hooks_createhook_callbacks) Instance used for disabling and enabling hooks Registers ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
7141b235-8afd-5656-bc49-63b441913c26
docs
nodejs
nodejs_async_hooks
11x
5
Note that the callbacks will be inherited via the prototype chain: ```None class MyAsyncCallbacks { init(asyncId, type, triggerAsyncId, resource) { } destroy(asyncId) {} } class MyAddedCallbacks extends MyAsyncCallbacks { before(asyncId) { } after(asyncId) { } } const asyncHook = async_hooks.createHook(new M...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
ec4a6091-16f7-5504-a414-9eb0923f6566
docs
nodejs
nodejs_async_hooks
11x
6
class construction and destruction. Because of this, it is deemed necessary to bring down the process quickly in order to prevent an unintentional abort in the future. This is subject to change in the future if a comprehensive analysis is performed to ensure an exception can follow the normal control flow without unint...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
e472cb09-230c-58f5-b237-beecc74cb7cd
docs
nodejs
nodejs_async_hooks
11x
7
// Use a function like this one when debugging inside an AsyncHooks callback fs.writeFileSync('log.out', `${util.format(...args)}\n`, { flag: 'a' }); } ``` If an asynchronous operation is needed for logging, it is possible to keep track of what caused the asynchronous operation using the information provided by As...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
fb3a84e2-e0f4-5a4e-95ca-137f181970d4
docs
nodejs
nodejs_async_hooks
11x
8
const hook = async_hooks.createHook(callbacks).enable(); ``` #### asyncHook.disable()[#](#async_hooks_asynchook_disable) * Returns: [<AsyncHook>](async_hooks.html#async_hooks_async_hooks_createhook_callbacks) A reference to `asyncHook`. Disable the callbacks for a given `AsyncHook` instance from the global pool of `...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
34495a14-6c20-5981-9bdb-6c0902621a7a
docs
nodejs
nodejs_async_hooks
11x
9
* `type` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The type of the async resource. * `triggerAsyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The unique ID of the async resource in whose execution context thi...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
c5dc3d85-9f7a-531e-8215-51af91a1fd1c
docs
nodejs
nodejs_async_hooks
11x
10
// OR clearTimeout(setTimeout(() => {}, 10)); ``` Every new resource is assigned an ID that is unique within the scope of the current Node.js instance. ###### `type`[#](#async_hooks_type) The `type` is a string identifying the type of resource that caused `init` to be called. Generally, it will correspond to the nam...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
cf68c9b2-4c08-593c-ac33-13d45344a549
docs
nodejs
nodejs_async_hooks
11x
11
unique prefixes, such as the npm package name, to prevent collisions when listening to the hooks. ###### `triggerAsyncId`[#](#async_hooks_triggerasyncid) `triggerAsyncId` is the `asyncId` of the resource that caused (or "triggered") the new resource to initialize and that caused `init` to call. This is different from...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
cea1a12e-78a2-5412-ba8b-91e42fcb9e52
docs
nodejs
nodejs_async_hooks
11x
12
The `TCPSERVERWRAP` is the server which receives the connections. The `TCPWRAP` is the new connection from the client. When a new connection is made, the `TCPWrap` instance is immediately constructed. This happens outside of any JavaScript stack. (An `executionAsyncId()` of `0` means that it is being executed from C++...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
1901af2a-261b-5a4f-b410-e20f81cca6a4
docs
nodejs
nodejs_async_hooks
11x
13
currently not considered public, but using the Embedder API, users can provide and document their own resource objects. For example, such a resource object could contain the SQL query being executed. In the case of Promises, the `resource` object will have `promise` property that refers to the `Promise` that is being ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
61ee5613-86d7-56ea-94ba-93626e7dad04
docs
nodejs
nodejs_async_hooks
11x
14
callback to `listen()` will look like. The output formatting is slightly more elaborate to make calling context easier to see. ```None let indent = 0; async_hooks.createHook({ init(asyncId, type, triggerAsyncId) { const eid = async_hooks.executionAsyncId(); const indentStr = ' '.repeat(indent); fs.writeS...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
75128a52-f42f-5f7d-b8ac-e85ffd2e7094
docs
nodejs
nodejs_async_hooks
11x
15
require('net').createServer(() => {}).listen(8080, () => { // Let's wait 10ms before logging the server started. setTimeout(() => { console.log('>>>', async_hooks.executionAsyncId()); }, 10); }); ``` Output from only starting the server: ```None TCPSERVERWRAP(5): trigger: 1 execution: 1 TickObject(6): trigg...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
925c6488-4221-5aac-b025-9aa75716be8c
docs
nodejs
nodejs_async_hooks
11x
16
hostname is a *synchronous* operation, but to maintain a completely asynchronous API the user's callback is placed in a `process.nextTick()`. The graph only shows *when* a resource was created, not *why*, so to track the *why* use `triggerAsyncId`. ##### before(asyncId)[#](#async_hooks_before_asyncid) * `asyncId` [<...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
2cb43ed7-8528-5162-9786-4b3f97a80879
docs
nodejs
nodejs_async_hooks
11x
17
asynchronous resources like a TCP server will typically call the `before` callback multiple times, while other operations like `fs.open()` will call it only once. ##### after(asyncId)[#](#async_hooks_after_asyncid) * `asyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_t...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
790dc5fb-453d-5f6d-b7f6-6ee06aed1ea7
docs
nodejs
nodejs_async_hooks
11x
18
made to the `resource` object passed to `init` it is possible that `destroy` will never be called, causing a memory leak in the application. If the resource does not depend on garbage collection, then this will not be an issue. ##### promiseResolve(asyncId)[#](#async_hooks_promiseresolve_asyncid) Added in: v8.6.0 * ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
536366cf-7921-5298-b94d-5d0569ada9b8
docs
nodejs
nodejs_async_hooks
11x
19
init for PROMISE with id 6, trigger id: 5 # the Promise returned by then() before 6 # the then() callback is entered promise resolve 6 # the then() callback resolves the promise by returning after 6 ``` #### async\_hooks.executionAsyncId()[#](#async_hooks_async_hooks_executionasyncid) Histor...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
e01d462d-e98b-51f0-a5c0-7c08d271e714
docs
nodejs
nodejs_async_hooks
11x
20
const server = net.createServer((conn) => { // Returns the ID of the server, not of the new connection, because the // callback runs in the execution scope of the server's MakeCallback(). async_hooks.executionAsyncId(); }).listen(port, () => { // Returns the ID of a TickObject (i.e. process.nextTick()) because...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
86e53271-5f58-56c3-a93c-623895d5f4cc
docs
nodejs
nodejs_async_hooks
11x
21
// was that of the new connection. Thus the return value of triggerAsyncId() // is the asyncId of "conn". async_hooks.triggerAsyncId(); }).listen(port, () => { // Even though all callbacks passed to .listen() are wrapped in a nextTick() // the callback itself exists because the call to the server's .listen()...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
5b530c7d-a744-57ba-a074-97fb48115c16
docs
nodejs
nodejs_async_hooks
11x
22
correct execution and trigger ids for promise callback contexts by default. ```None const ah = require('async_hooks'); Promise.resolve(1729).then(() => { console.log(`eid ${ah.executionAsyncId()} tid ${ah.triggerAsyncId()}`); }); // produces: // eid 1 tid 0 ``` Observe that the `then()` callback claims to have exec...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
88b3a9a4-5d84-5335-8431-98ecb254e855
docs
nodejs
nodejs_async_hooks
11x
23
promises. There are two promises in the example above; the promise created by `Promise.resolve()` and the promise returned by the call to `then()`. In the example above, the first promise got the `asyncId` `6` and the latter got `asyncId` `7`. During the execution of the `then()` callback, we are executing in the conte...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
9989fba5-2085-5756-9d2e-3077d6ac223c
docs
nodejs
nodejs_async_hooks
11x
24
`AsyncWrap` JavaScript API so that all the appropriate callbacks are called. ### Class: AsyncResource[[src]](https://github.com/nodejs/node/blob/v11.15.0^0/lib/async_hooks.js#L141)[#](#async_hooks_class_asyncresource) The class `AsyncResource` is designed to be extended by the embedder's async resources. Using this, ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
25b188fa-c031-5a4a-acff-0e527efea652
docs
nodejs
nodejs_async_hooks
11x
25
// * trigger the AsyncHooks before callbacks // * call the provided function `fn` with the supplied arguments // * trigger the AsyncHooks after callbacks // * restore the original execution context asyncResource.runInAsyncScope(fn, thisArg, ...args); // Call AsyncHooks destroy callbacks. asyncResource.emitDestroy(); ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
4f730e85-a266-58eb-a5af-3c041ec68e56
docs
nodejs
nodejs_async_hooks
11x
26
+ `triggerAsyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The ID of the execution context that created this async event. **Default:** `executionAsyncId()`. + `requireManualDestroy` [<boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
df6a963b-19a7-5056-b921-a212b5614b42
docs
nodejs
nodejs_async_hooks
11x
27
#### asyncResource.runInAsyncScope(fn[, thisArg, ...args])[[src]](https://github.com/nodejs/node/blob/v11.15.0^0/lib/async_hooks.js#L184)[#](#async_hooks_asyncresource_runinasyncscope_fn_thisarg_args) Added in: v9.6.0 * `fn` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
42365181-f965-5e4f-b8e9-7cbf407a21c9
docs
nodejs
nodejs_async_hooks
11x
28
#### asyncResource.emitBefore()[[src]](https://github.com/nodejs/node/blob/v11.15.0^0/lib/async_hooks.js#L172)[#](#async_hooks_asyncresource_emitbefore) Deprecated since: v9.6.0 [Stability: 0](documentation.html#documentation_stability_index) - Deprecated: Use [`asyncResource.runInAsyncScope()`](#async_hooks_asyncres...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
8be6dab1-4687-59f6-8265-89025a24398d
docs
nodejs
nodejs_async_hooks
11x
29
#### asyncResource.emitAfter()[[src]](https://github.com/nodejs/node/blob/v11.15.0^0/lib/async_hooks.js#L178)[#](#async_hooks_asyncresource_emitafter) Deprecated since: v9.6.0 [Stability: 0](documentation.html#documentation_stability_index) - Deprecated: Use [`asyncResource.runInAsyncScope()`](#async_hooks_asyncresou...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
dd54fc06-71e7-5536-a6f6-25472e26744c
docs
nodejs
nodejs_async_hooks
11x
30
#### asyncResource.emitDestroy()[[src]](https://github.com/nodejs/node/blob/v11.15.0^0/lib/async_hooks.js#L195)[#](#async_hooks_asyncresource_emitdestroy) * Returns: [<AsyncResource>](async_hooks.html#async_hooks_class_asyncresource) A reference to `asyncResource`. Call all `destroy` hooks. This should only ever be ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
c4bfabf4-4b53-5e36-b512-89b98467ffbf
docs
nodejs
nodejs_async_hooks
11x
31
#### asyncResource.triggerAsyncId()[[src]](https://github.com/nodejs/node/blob/v11.15.0^0/lib/async_hooks.js#L205)[#](#async_hooks_asyncresource_triggerasyncid) * Returns: [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The same `triggerAsyncId` that is passed to the `...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_11x.md
95ef2e7e-5d6a-5ed3-bbeb-576047e92c5c
docs
nodejs
nodejs_async_hooks
8x
0
# Async Hooks# Source: https://nodejs.org/docs/latest-v8.x/api/async_hooks.html Version: 8.x [Stability: 1](documentation.html#documentation_stability_index) - Experimental The `async_hooks` module provides an API to register callbacks tracking the lifetime of asynchronous resources created inside a Node.js applicat...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
bb16bf53-6721-5139-bd8c-ff5b1778668e
docs
nodejs
nodejs_async_hooks
8x
1
## Public API[#](#async_hooks_public_api) ### Overview[#](#async_hooks_overview) Following is a simple overview of the public API. ```None const async_hooks = require('async_hooks'); // Return the ID of the current execution context. const eid = async_hooks.executionAsyncId(); // Return the ID of the handle respon...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
b685a9e8-94a3-5d80-82cd-1d85de9dea4c
docs
nodejs
nodejs_async_hooks
8x
2
// init is called during object construction. The resource may not have // completed construction when this callback runs, therefore all fields of the // resource referenced by "asyncId" may not have been populated. function init(asyncId, type, triggerAsyncId, resource) { } // before is called just before the resource...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
1b83f73b-1261-5a92-8e26-9480ebd305b5
docs
nodejs
nodejs_async_hooks
8x
3
#### `async_hooks.createHook(callbacks)`[#](#async_hooks_async_hooks_createhook_callbacks) Added in: v8.1.0 * `callbacks` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) The [Hook Callbacks](#async_hooks_hook_callbacks) to register + `init` [<Function>](https://de...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
2d36d587-8992-5737-912e-f73cf9e83040
docs
nodejs
nodejs_async_hooks
8x
4
* Returns: [<AsyncHook>](async_hooks.html#async_hooks_async_hooks_createhook_callbacks) Instance used for disabling and enabling hooks Registers functions to be called for different lifetime events of each async operation. The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the respective asynchron...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
5afbdc9f-17bf-55a5-a775-a9a45423c890
docs
nodejs
nodejs_async_hooks
8x
5
class MyAddedCallbacks extends MyAsyncCallbacks { before(asyncId) { } after(asyncId) { } } const asyncHook = async_hooks.createHook(new MyAddedCallbacks()); ``` ##### Error Handling[#](#async_hooks_error_handling) If any `AsyncHook` callbacks throw, the application will print the stack trace and exit. The exit p...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
97b9468b-f9ed-54e7-b4c9-61fa439df650
docs
nodejs
nodejs_async_hooks
8x
6
future. This is subject to change in the future if a comprehensive analysis is performed to ensure an exception can follow the normal control flow without unintentional side effects. ##### Printing in AsyncHooks callbacks[#](#async_hooks_printing_in_asynchooks_callbacks) Because printing to the console is an asynchro...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
bea20c7c-318d-5e82-b263-347cb4597078
docs
nodejs
nodejs_async_hooks
8x
7
If an asynchronous operation is needed for logging, it is possible to keep track of what caused the asynchronous operation using the information provided by AsyncHooks itself. The logging should then be skipped when it was the logging itself that caused AsyncHooks callback to call. By doing this the otherwise infinite ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
b23d9692-1686-5c08-ac4f-2ca1ab09ed94
docs
nodejs
nodejs_async_hooks
8x
8
#### `asyncHook.disable()`[#](#async_hooks_asynchook_disable) * Returns: [<AsyncHook>](async_hooks.html#async_hooks_async_hooks_createhook_callbacks) A reference to `asyncHook`. Disable the callbacks for a given `AsyncHook` instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disa...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
60c425e2-c4a3-5098-9b33-43fb8033d941
docs
nodejs
nodejs_async_hooks
8x
9
* `type` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The type of the async resource. * `triggerAsyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The unique ID of the async resource in whose execution context thi...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
266f1c86-a329-5363-a592-d3fca5934542
docs
nodejs
nodejs_async_hooks
8x
10
// OR clearTimeout(setTimeout(() => {}, 10)); ``` Every new resource is assigned an ID that is unique within the scope of the current process. ###### `type`[#](#async_hooks_type) The `type` is a string identifying the type of resource that caused `init` to be called. Generally, it will correspond to the name of the ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
d9956476-c666-5244-946e-07d3cc87c287
docs
nodejs
nodejs_async_hooks
8x
11
to use unique prefixes, such as the npm package name, to prevent collisions when listening to the hooks. ###### `triggerId`[#](#async_hooks_triggerid) `triggerAsyncId` is the `asyncId` of the resource that caused (or "triggered") the new resource to initialize and that caused `init` to call. This is different from `a...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
8d3521f8-94df-5f60-a01e-c7d6ae685935
docs
nodejs
nodejs_async_hooks
8x
12
The `TCPSERVERWRAP` is the server which receives the connections. The `TCPWRAP` is the new connection from the client. When a new connection is made the `TCPWrap` instance is immediately constructed. This happens outside of any JavaScript stack (side note: a `executionAsyncId()` of `0` means it's being executed from C...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
e3216cb6-eb67-54bf-a705-39053ff233a3
docs
nodejs
nodejs_async_hooks
8x
13
hostname in `net.Server.listen()`. The API for accessing this information is currently not considered public, but using the Embedder API, users can provide and document their own resource objects. For example, such a resource object could contain the SQL query being executed. In the case of Promises, the `resource` ob...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
911c07d6-b7f4-5e22-8181-6b0a57610f8c
docs
nodejs
nodejs_async_hooks
8x
14
###### Asynchronous context example[#](#async_hooks_asynchronous_context_example) The following is an example with additional information about the calls to `init` between the `before` and `after` calls, specifically what the callback to `listen()` will look like. The output formatting is slightly more elaborate to ma...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
1d636e63-0850-5bbf-be01-da416b46aba8
docs
nodejs
nodejs_async_hooks
8x
15
fs.writeSync(1, `${indentStr}destroy: ${asyncId}\n`); }, }).enable(); require('net').createServer(() => {}).listen(8080, () => { // Let's wait 10ms before logging the server started. setTimeout(() => { console.log('>>>', async_hooks.executionAsyncId()); }, 10); }); ``` Output from only starting the se...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
8ba47834-7b75-55a7-a391-642900e2e913
docs
nodejs
nodejs_async_hooks
8x
16
Only using `execution` to graph resource allocation results in the following: ```None TTYWRAP(6) -> Timeout(4) -> TIMERWRAP(5) -> TickObject(3) -> root(1) ``` The `TCPSERVERWRAP` is not part of this graph, even though it was the reason for `console.log()` being called. This is because binding to a port without a host...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
fd0e8215-0fe9-5923-9dd4-9da90e2f6362
docs
nodejs
nodejs_async_hooks
8x
17
callback is executed. `asyncId` is the unique identifier assigned to the resource about to execute the callback. The `before` callback will be called 0 to N times. The `before` callback will typically be called 0 times if the asynchronous operation was cancelled or, for example, if no connections are received by a TCP...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
67e87a07-bbfb-5fb8-9ca3-c98f9795f855
docs
nodejs
nodejs_async_hooks
8x
18
##### `destroy(asyncId)`[#](#async_hooks_destroy_asyncid) * `asyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Called after the resource corresponding to `asyncId` is destroyed. It is also called asynchronously from the embedder API `emitDestroy()`. *Note:* Some...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
db77640e-bce5-5442-ad16-d6dc4b1a6b74
docs
nodejs
nodejs_async_hooks
8x
19
*Note:* This does not necessarily mean that the `Promise` is fulfilled or rejected at this point, if the `Promise` was resolved by assuming the state of another `Promise`. For example: ```None new Promise((resolve) => resolve(true)).then((a) => {}); ``` calls the following callbacks: ```None init for PROMISE with i...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
3fc41218-9309-5030-87f7-02ced03122b0
docs
nodejs
nodejs_async_hooks
8x
20
For example: ```None const async_hooks = require('async_hooks'); console.log(async_hooks.executionAsyncId()); // 1 - bootstrap fs.open(path, 'r', (err, fd) => { console.log(async_hooks.executionAsyncId()); // 6 - open() }); ``` The ID returned from `executionAsyncId()` is related to execution timing, not causali...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
55c9ffb8-9e66-595e-9c3c-329388a77e05
docs
nodejs
nodejs_async_hooks
8x
21
See the section on [promise execution tracking](#async_hooks_promise_execution_tracking). #### `async_hooks.triggerAsyncId()`[#](#async_hooks_async_hooks_triggerasyncid) * Returns: [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The ID of the resource responsible for ca...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
327efdeb-003e-5802-94e4-86a7c52cb01b
docs
nodejs
nodejs_async_hooks
8x
22
the section on [promise execution tracking](#async_hooks_promise_execution_tracking). ## Promise execution tracking[#](#async_hooks_promise_execution_tracking) By default, promise executions are not assigned asyncIds due to the relatively expensive nature of the [promise introspection API](https://docs.google.com/doc...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
9ea13214-a814-5546-8579-d4576bc9ba91
docs
nodejs
nodejs_async_hooks
8x
23
resource that caused (triggered) the `then` callback to be executed. Installing async hooks via `async_hooks.createHook` enables promise execution tracking. Example: ```None const ah = require('async_hooks'); ah.createHook({ init() {} }).enable(); // forces PromiseHooks to be enabled. Promise.resolve(1729).then(() =>...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
f1082932-6b27-5d7f-8fbc-bdd859c2bfdf
docs
nodejs
nodejs_async_hooks
8x
24
only on chained promises. That means promises not created by `then`/`catch` will not have the `before` and `after` callbacks fired on them. For more details see the details of the V8 [PromiseHooks](https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk) API. ## JavaScript Embedder API[#](#asyn...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
888aa2ea-07f6-5683-8ce2-2f1a0e84f2ae
docs
nodejs
nodejs_async_hooks
8x
25
// AsyncResource() is meant to be extended. Instantiating a // new AsyncResource() also triggers init. If triggerAsyncId is omitted then // async_hook.executionAsyncId() is used. const asyncResource = new AsyncResource( type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false } ); // Run a function in...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
44efc25a-34cb-5cfa-afa2-956533b7cec9
docs
nodejs
nodejs_async_hooks
8x
26
asyncResource.emitBefore(); // Call AsyncHooks after callbacks. // Deprecated: Use asyncResource.runInAsyncScope instead. asyncResource.emitAfter(); ``` #### `AsyncResource(type[, options])`[#](#async_hooks_asyncresource_type_options) * `type` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_s...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
f617c470-fc50-5a2d-9225-68c2fb324765
docs
nodejs
nodejs_async_hooks
8x
27
`emitDestroy` is called manually), unless the resource's asyncId is retrieved and the sensitive API's `emitDestroy` is called with it. **Default:** `false`. Example usage: ```None class DBQuery extends AsyncResource { constructor(db) { super('DBQuery'); this.db = db; } getInfo(query, callback) ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
39e30848-b6a9-5350-8965-4f4abf895590
docs
nodejs
nodejs_async_hooks
8x
28
Call the provided function with the provided arguments in the execution context of the async resource. This will establish the context, trigger the AsyncHooks before callbacks, call the function, trigger the AsyncHooks after callbacks, and then restore the original execution context. #### `asyncResource.emitBefore()`[...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
10f76ed1-29f4-5d12-be85-27ea9a6e8b12
docs
nodejs
nodejs_async_hooks
8x
29
are called. Otherwise, an unrecoverable exception will occur and the process will abort. For this reason, the `emitBefore` and `emitAfter` APIs are considered deprecated. Please use `runInAsyncScope`, as it provides a much safer alternative. #### `asyncResource.emitAfter()`[#](#async_hooks_asyncresource_emitafter) De...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
93dcbf25-5f2d-5e32-a261-3fbebe9a8990
docs
nodejs
nodejs_async_hooks
8x
30
`before` and `after` calls must be unwound in the same order that they are called. Otherwise, an unrecoverable exception will occur and the process will abort. For this reason, the `emitBefore` and `emitAfter` APIs are considered deprecated. Please use `runInAsyncScope`, as it provides a much safer alternative. #### `...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
1bb8b072-5e3f-57cc-b5b6-0c39f62466bf
docs
nodejs
nodejs_async_hooks
8x
31
#### `asyncResource.triggerAsyncId()`[#](#async_hooks_asyncresource_triggerasyncid) * Returns: [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_8x.md
6ebb4817-5bc2-58ab-9250-a1e5321b984b
docs
nodejs
nodejs_async_hooks
9x
0
# Async Hooks# Source: https://nodejs.org/docs/latest-v9.x/api/async_hooks.html Version: 9.x [Stability: 1](documentation.html#documentation_stability_index) - Experimental The `async_hooks` module provides an API to register callbacks tracking the lifetime of asynchronous resources created inside a Node.js applicat...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
da908357-c8e4-54e5-a711-ccb8a0fb1bdf
docs
nodejs
nodejs_async_hooks
9x
1
## Public API[#](#async_hooks_public_api) ### Overview[#](#async_hooks_overview) Following is a simple overview of the public API. ```None const async_hooks = require('async_hooks'); // Return the ID of the current execution context. const eid = async_hooks.executionAsyncId(); // Return the ID of the handle respon...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
9b9c7ac1-451d-595a-81bb-ca8d7396280e
docs
nodejs
nodejs_async_hooks
9x
2
// init is called during object construction. The resource may not have // completed construction when this callback runs, therefore all fields of the // resource referenced by "asyncId" may not have been populated. function init(asyncId, type, triggerAsyncId, resource) { } // before is called just before the resource...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
5e1124ed-0495-5a98-bff4-50c630c48105
docs
nodejs
nodejs_async_hooks
9x
3
#### `async_hooks.createHook(callbacks)`[#](#async_hooks_async_hooks_createhook_callbacks) Added in: v8.1.0 * `callbacks` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) The [Hook Callbacks](#async_hooks_hook_callbacks) to register + `init` [<Function>](https://de...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
fcc78ab0-b1b4-5472-9f38-b0d1d4d2e9a6
docs
nodejs
nodejs_async_hooks
9x
4
* Returns: [<AsyncHook>](async_hooks.html#async_hooks_async_hooks_createhook_callbacks) Instance used for disabling and enabling hooks Registers functions to be called for different lifetime events of each async operation. The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the respective asynchron...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
c60947e7-f8f5-5ecc-a510-b8ef1d2d7f92
docs
nodejs
nodejs_async_hooks
9x
5
class MyAddedCallbacks extends MyAsyncCallbacks { before(asyncId) { } after(asyncId) { } } const asyncHook = async_hooks.createHook(new MyAddedCallbacks()); ``` ##### Error Handling[#](#async_hooks_error_handling) If any `AsyncHook` callbacks throw, the application will print the stack trace and exit. The exit p...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
25b8b9e7-da1c-5276-84e6-f4fdac420279
docs
nodejs
nodejs_async_hooks
9x
6
future. This is subject to change in the future if a comprehensive analysis is performed to ensure an exception can follow the normal control flow without unintentional side effects. ##### Printing in AsyncHooks callbacks[#](#async_hooks_printing_in_asynchooks_callbacks) Because printing to the console is an asynchro...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
dd86439d-a4ce-53c7-b874-3abfe101fd03
docs
nodejs
nodejs_async_hooks
9x
7
If an asynchronous operation is needed for logging, it is possible to keep track of what caused the asynchronous operation using the information provided by AsyncHooks itself. The logging should then be skipped when it was the logging itself that caused AsyncHooks callback to call. By doing this the otherwise infinite ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
f8398700-f545-535a-8ad8-990af7a3e029
docs
nodejs
nodejs_async_hooks
9x
8
#### `asyncHook.disable()`[#](#async_hooks_asynchook_disable) * Returns: [<AsyncHook>](async_hooks.html#async_hooks_async_hooks_createhook_callbacks) A reference to `asyncHook`. Disable the callbacks for a given `AsyncHook` instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disa...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
e5f232bb-d985-5452-a94e-4ed204e84e8d
docs
nodejs
nodejs_async_hooks
9x
9
* `type` [<string>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The type of the async resource. * `triggerAsyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The unique ID of the async resource in whose execution context thi...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
32abf328-9c55-5caf-8ee2-adb4dd60d1f0
docs
nodejs
nodejs_async_hooks
9x
10
// OR clearTimeout(setTimeout(() => {}, 10)); ``` Every new resource is assigned an ID that is unique within the scope of the current process. ###### `type`[#](#async_hooks_type) The `type` is a string identifying the type of resource that caused `init` to be called. Generally, it will correspond to the name of the ...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
1e12d301-4ab0-5e72-bdc6-3f7fd0e59715
docs
nodejs
nodejs_async_hooks
9x
11
to use unique prefixes, such as the npm package name, to prevent collisions when listening to the hooks. ###### `triggerId`[#](#async_hooks_triggerid) `triggerAsyncId` is the `asyncId` of the resource that caused (or "triggered") the new resource to initialize and that caused `init` to call. This is different from `a...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
6ba9d311-7f15-5b1d-a2fb-4037412f055f
docs
nodejs
nodejs_async_hooks
9x
12
The `TCPSERVERWRAP` is the server which receives the connections. The `TCPWRAP` is the new connection from the client. When a new connection is made the `TCPWrap` instance is immediately constructed. This happens outside of any JavaScript stack (side note: a `executionAsyncId()` of `0` means it's being executed from C...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
96a49be4-2f87-56b6-8f36-fd6a2ac2369a
docs
nodejs
nodejs_async_hooks
9x
13
hostname in `net.Server.listen()`. The API for accessing this information is currently not considered public, but using the Embedder API, users can provide and document their own resource objects. For example, such a resource object could contain the SQL query being executed. In the case of Promises, the `resource` ob...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
9724da54-6b1b-53a2-b086-353f7a5de5f5
docs
nodejs
nodejs_async_hooks
9x
14
###### Asynchronous context example[#](#async_hooks_asynchronous_context_example) The following is an example with additional information about the calls to `init` between the `before` and `after` calls, specifically what the callback to `listen()` will look like. The output formatting is slightly more elaborate to ma...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
4e7a8817-cb5f-565a-baeb-4c77eb8e954a
docs
nodejs
nodejs_async_hooks
9x
15
fs.writeSync(1, `${indentStr}destroy: ${asyncId}\n`); }, }).enable(); require('net').createServer(() => {}).listen(8080, () => { // Let's wait 10ms before logging the server started. setTimeout(() => { console.log('>>>', async_hooks.executionAsyncId()); }, 10); }); ``` Output from only starting the se...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
60512a1f-4f3e-520a-8aff-b42da604893b
docs
nodejs
nodejs_async_hooks
9x
16
Only using `execution` to graph resource allocation results in the following: ```None TTYWRAP(6) -> Timeout(4) -> TIMERWRAP(5) -> TickObject(3) -> root(1) ``` The `TCPSERVERWRAP` is not part of this graph, even though it was the reason for `console.log()` being called. This is because binding to a port without a host...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
c224c27a-add6-5311-a910-1219bd5b54de
docs
nodejs
nodejs_async_hooks
9x
17
callback is executed. `asyncId` is the unique identifier assigned to the resource about to execute the callback. The `before` callback will be called 0 to N times. The `before` callback will typically be called 0 times if the asynchronous operation was cancelled or, for example, if no connections are received by a TCP...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
b6afa33f-b346-5262-bf66-0ac283ed06df
docs
nodejs
nodejs_async_hooks
9x
18
##### `destroy(asyncId)`[#](#async_hooks_destroy_asyncid) * `asyncId` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Called after the resource corresponding to `asyncId` is destroyed. It is also called asynchronously from the embedder API `emitDestroy()`. *Note:* Some...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
959d2ca0-2520-52c3-b69a-5c8cd59167ed
docs
nodejs
nodejs_async_hooks
9x
19
*Note:* This does not necessarily mean that the `Promise` is fulfilled or rejected at this point, if the `Promise` was resolved by assuming the state of another `Promise`. ```None new Promise((resolve) => resolve(true)).then((a) => {}); ``` calls the following callbacks: ```None init for PROMISE with id 5, trigger i...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
8ef883f9-1080-591d-99bd-9d82c667de8c
docs
nodejs
nodejs_async_hooks
9x
20
const async_hooks = require('async_hooks'); console.log(async_hooks.executionAsyncId()); // 1 - bootstrap fs.open(path, 'r', (err, fd) => { console.log(async_hooks.executionAsyncId()); // 6 - open() }); ``` The ID returned from `executionAsyncId()` is related to execution timing, not causality (which is covered b...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
2913aaca-36f7-5183-8a21-e19fa401d02b
docs
nodejs
nodejs_async_hooks
9x
21
#### `async_hooks.triggerAsyncId()`[#](#async_hooks_async_hooks_triggerasyncid) * Returns: [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The ID of the resource responsible for calling the callback that is currently being executed. ```None const server = net.createSe...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md
c647ad98-adcb-5585-9d67-dd8014973e9c
docs
nodejs
nodejs_async_hooks
9x
22
## Promise execution tracking[#](#async_hooks_promise_execution_tracking) By default, promise executions are not assigned asyncIds due to the relatively expensive nature of the [promise introspection API](https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk) provided by V8. This means that p...
large_dataset/raw/docs/nodejs/async_hooks/async_hooks_9x.md