@@ -25,9 +25,7 @@ as the abstract concept that is a resource.
2525If [ ` Worker ` ] [ ] s are used, each thread has an independent ` async_hooks `
2626interface, and each thread will use a new set of async IDs.
2727
28- ## Public API
29-
30- ### Overview
28+ ## Overview
3129
3230Following is a simple overview of the public API.
3331
@@ -79,7 +77,7 @@ function destroy(asyncId) { }
7977function promiseResolve (asyncId ) { }
8078```
8179
82- #### ` async_hooks.createHook(callbacks) `
80+ ## ` async_hooks.createHook(callbacks) `
8381
8482<!-- YAML
8583added: v8.1.0
@@ -133,7 +131,7 @@ Because promises are asynchronous resources whose lifecycle is tracked
133131via the async hooks mechanism, the ` init() ` , ` before() ` , ` after() ` , and
134132` destroy() ` callbacks * must not* be async functions that return promises.
135133
136- ##### Error handling
134+ ### Error handling
137135
138136If any ` AsyncHook ` callbacks throw, the application will print the stack trace
139137and exit. The exit path does follow that of an uncaught exception, but
@@ -150,7 +148,7 @@ future. This is subject to change in the future if a comprehensive analysis is
150148performed to ensure an exception can follow the normal control flow without
151149unintentional side effects.
152150
153- ##### Printing in AsyncHooks callbacks
151+ ### Printing in AsyncHooks callbacks
154152
155153Because printing to the console is an asynchronous operation, ` console.log() `
156154will cause the AsyncHooks callbacks to be called. Using ` console.log() ` or
@@ -176,12 +174,12 @@ provided by AsyncHooks itself. The logging should then be skipped when
176174it was the logging itself that caused AsyncHooks callback to call. By
177175doing this the otherwise infinite recursion is broken.
178176
179- ### Class: ` AsyncHook `
177+ ## Class: ` AsyncHook `
180178
181179The class ` AsyncHook ` exposes an interface for tracking lifetime events
182180of asynchronous operations.
183181
184- #### ` asyncHook.enable() `
182+ ### ` asyncHook.enable() `
185183
186184* Returns: {AsyncHook} A reference to ` asyncHook ` .
187185
@@ -197,7 +195,7 @@ const async_hooks = require('async_hooks');
197195const hook = async_hooks .createHook (callbacks).enable ();
198196```
199197
200- #### ` asyncHook.disable() `
198+ ### ` asyncHook.disable() `
201199
202200* Returns: {AsyncHook} A reference to ` asyncHook ` .
203201
@@ -207,13 +205,13 @@ be called again until enabled.
207205
208206For API consistency ` disable() ` also returns the ` AsyncHook ` instance.
209207
210- #### Hook callbacks
208+ ### Hook callbacks
211209
212210Key events in the lifetime of asynchronous events have been categorized into
213211four areas: instantiation, before/after the callback is called, and when the
214212instance is destroyed.
215213
216- ##### ` init(asyncId, type, triggerAsyncId, resource) `
214+ #### ` init(asyncId, type, triggerAsyncId, resource) `
217215
218216* ` asyncId ` {number} A unique ID for the async resource.
219217* ` type ` {string} The type of the async resource.
@@ -240,7 +238,7 @@ clearTimeout(setTimeout(() => {}, 10));
240238Every new resource is assigned an ID that is unique within the scope of the
241239current Node.js instance.
242240
243- ###### ` type `
241+ ##### ` type `
244242
245243The ` type ` is a string identifying the type of resource that caused
246244` init ` to be called. Generally, it will correspond to the name of the
@@ -263,7 +261,7 @@ It is possible to have type name collisions. Embedders are encouraged to use
263261unique prefixes, such as the npm package name, to prevent collisions when
264262listening to the hooks.
265263
266- ###### ` triggerAsyncId `
264+ ##### ` triggerAsyncId `
267265
268266` triggerAsyncId ` is the ` asyncId ` of the resource that caused (or "triggered")
269267the new resource to initialize and that caused ` init ` to call. This is different
@@ -302,7 +300,7 @@ that information, it would be impossible to link resources together in
302300terms of what caused them to be created, so ` triggerAsyncId ` is given the task
303301of propagating what resource is responsible for the new resource's existence.
304302
305- ###### ` resource `
303+ ##### ` resource `
306304
307305` resource ` is an object that represents the actual async resource that has
308306been initialized. This can contain useful information that can vary based on
@@ -316,7 +314,7 @@ could contain the SQL query being executed.
316314In some cases the resource object is reused for performance reasons, it is
317315thus not safe to use it as a key in a ` WeakMap ` or add properties to it.
318316
319- ###### Asynchronous context example
317+ ##### Asynchronous context example
320318
321319The following is an example with additional information about the calls to
322320` init ` between the ` before ` and ` after ` calls, specifically what the
@@ -415,7 +413,7 @@ TCPSERVERWRAP(5)
415413 Timeout(7)
416414```
417415
418- ##### ` before(asyncId) `
416+ #### ` before(asyncId) `
419417
420418* ` asyncId ` {number}
421419
@@ -432,7 +430,7 @@ asynchronous resources like a TCP server will typically call the `before`
432430callback multiple times, while other operations like ` fs.open() ` will call
433431it only once.
434432
435- ##### ` after(asyncId) `
433+ #### ` after(asyncId) `
436434
437435* ` asyncId ` {number}
438436
@@ -442,7 +440,7 @@ If an uncaught exception occurs during execution of the callback, then `after`
442440will run * after* the ` 'uncaughtException' ` event is emitted or a ` domain ` 's
443441handler runs.
444442
445- ##### ` destroy(asyncId) `
443+ #### ` destroy(asyncId) `
446444
447445* ` asyncId ` {number}
448446
@@ -454,7 +452,7 @@ made to the `resource` object passed to `init` it is possible that `destroy`
454452will never be called, causing a memory leak in the application. If the resource
455453does not depend on garbage collection, then this will not be an issue.
456454
457- ##### ` promiseResolve(asyncId) `
455+ #### ` promiseResolve(asyncId) `
458456
459457<!-- YAML
460458added: v8.6.0
@@ -485,7 +483,7 @@ init for PROMISE with id 6, trigger id: 5 # the Promise returned by then()
485483 after 6
486484```
487485
488- #### ` async_hooks.executionAsyncResource() `
486+ ### ` async_hooks.executionAsyncResource() `
489487
490488<!-- YAML
491489added:
@@ -543,7 +541,7 @@ const server = createServer((req, res) => {
543541}).listen (3000 );
544542```
545543
546- #### ` async_hooks.executionAsyncId() `
544+ ### ` async_hooks.executionAsyncId() `
547545
548546<!-- YAML
549547added: v8.1.0
@@ -584,7 +582,7 @@ const server = net.createServer((conn) => {
584582Promise contexts may not get precise ` executionAsyncIds ` by default.
585583See the section on [ promise execution tracking] [ ] .
586584
587- #### ` async_hooks.triggerAsyncId() `
585+ ### ` async_hooks.triggerAsyncId() `
588586
589587* Returns: {number} The ID of the resource responsible for calling the callback
590588 that is currently being executed.
0 commit comments