-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
docs: documenting async hooks features #13287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
59088f3
1e35d73
c5db0a6
3218d31
aa830d7
d09735f
fa37457
9b9cc15
affa7a7
1f23ab2
47a51c1
9864609
de40c74
7c9ecd4
de82ef4
d3ee97e
4ba706f
82149a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,10 @@ Following is a simple overview of the public API. | |
| ```js | ||
| const async_hooks = require('async_hooks'); | ||
|
|
||
| // Return the id of the current execution context. | ||
| // Return the ID of the current execution context. | ||
| const cid = async_hooks.currentId(); | ||
|
|
||
| // Return the id of the handle responsible for triggering the callback of the | ||
| // Return the ID of the handle responsible for triggering the callback of the | ||
| // current execution scope to fire. | ||
| const tid = async_hooks.triggerId(); | ||
|
|
||
|
|
@@ -165,9 +165,9 @@ destructor calls are emulated. | |
|
|
||
| ##### `init(id, type, triggerId, resource)` | ||
|
|
||
| * `id` {number} a unique id for the async resource | ||
| * `id` {number} a unique ID for the async resource | ||
| * `type` {string} the type of the async resource | ||
| * `triggerId` {number} the unique id of the async resource in whose | ||
| * `triggerId` {number} the unique ID of the async resource in whose | ||
| execution context this async resource was created | ||
| * `resource` {Object} reference to the resource representing the async operation, | ||
| needs to be released during _destroy_ | ||
|
|
@@ -187,7 +187,7 @@ require('net').createServer().listen(function() { this.close() }); | |
| clearTimeout(setTimeout(() => {}, 10)); | ||
| ``` | ||
|
|
||
| Every new resource is assigned a unique id. | ||
| Every new resource is assigned a unique ID. | ||
|
|
||
| The `type` is a string that represents the type of resource that caused | ||
| `init()` to fire. Generally it will be the name of the resource's constructor. | ||
|
|
@@ -370,27 +370,27 @@ fs.open(path, (err, fd) => { | |
| }): | ||
| ``` | ||
|
|
||
| It is important to note that the id returned fom `currentId()` is related to | ||
| It is important to note that the ID returned fom `currentId()` is related to | ||
| execution timing, not causality (which is covered by `triggerId()`). For | ||
| example: | ||
|
|
||
| ```js | ||
| const server = net.createServer(function onConnection(conn) { | ||
| // Returns the id of the server, not of the new connection, because the | ||
| // Returns the ID of the server, not of the new connection, because the | ||
| // onConnection callback runs in the execution scope of the server's | ||
| // MakeCallback(). | ||
| async_hooks.currentId(); | ||
|
|
||
| }).listen(port, function onListening() { | ||
| // Returns the id of a TickObject (i.e. process.nextTick()) because all | ||
| // Returns the ID of a TickObject (i.e. process.nextTick()) because all | ||
| // callbacks passed to .listen() are wrapped in a nextTick(). | ||
| async_hooks.currentId(); | ||
| }); | ||
| ``` | ||
|
|
||
| #### `async_hooks.triggerId()` | ||
|
|
||
| * Returns {number} the id of the resource responsible for calling the callback | ||
| * Returns {number} the ID of the resource responsible for calling the callback | ||
| that is currently being executed. | ||
|
|
||
| For example: | ||
|
|
@@ -399,13 +399,13 @@ For example: | |
| const server = net.createServer(conn => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we run the linter on docs now, so this might need to be |
||
| // Though the resource that caused (or triggered) this callback to | ||
| // be called was that of the new connection. Thus the return value | ||
| // of triggerId() is the id of "conn". | ||
| // of triggerId() is the ID of "conn". | ||
| async_hooks.triggerId(); | ||
|
|
||
| }).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() | ||
| // was made. So the return value would be the id of the server. | ||
| // was made. So the return value would be the ID of the server. | ||
| async_hooks.triggerId(); | ||
| }); | ||
| ``` | ||
|
|
@@ -443,18 +443,18 @@ asyncResource.emitAfter(); | |
| // Call destroy() hooks. | ||
| asyncResource.emitDestroy(); | ||
|
|
||
| // Return the unique id assigned to the AsyncResource instance. | ||
| // Return the unique ID assigned to the AsyncResource instance. | ||
| asyncResource.asyncId(); | ||
|
|
||
| // Return the trigger id for the AsyncResource instance. | ||
| // Return the trigger ID for the AsyncResource instance. | ||
| asyncResource.triggerId(); | ||
| ``` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is supposed to be an API overview then it should probably have the sub-heading that says that. But it may also want to be removed, like I discussed above or the other similar section. |
||
|
|
||
| #### `AsyncResource(type[, triggerId])` | ||
|
|
||
| * arguments | ||
| * `type` {string} the type of ascycn event | ||
| * `triggerId` {number} the id of the execution context that created this async | ||
| * `triggerId` {number} the ID of the execution context that created this async | ||
| event | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add that the default is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, we can't document details in the summary. |
||
| * Returns {AsyncResource} A reference to `asyncHook`. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code has replaced
idwithasyncIdfor consistency and to always be more explicit about which id is being referred to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like there's a lot of content in here that should either have it's own sub-header under
init()or moved to it's own sub-header underAsync Hooks.