-
-
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 |
|---|---|---|
|
|
@@ -395,51 +395,52 @@ Library developers that handle their own I/O will need to hook into the | |
| AsyncWrap API so that all the appropriate callbacks are called. To accommodate | ||
| this a JavaScript API is provided. | ||
|
|
||
| ### `class AsyncEvent()` | ||
| ### `class AsyncResource()` | ||
|
|
||
| The class `AsyncEvent` was designed to be extended by the embedder's async | ||
| The class `AsyncResource` was designed to be extended by the embedder's async | ||
| resources. Using this users can easily trigger the lifetime events of their | ||
| own resources. | ||
|
|
||
| The `init()` hook will trigger when an `AsyncEvent` is instantiated. | ||
| The `init()` hook will trigger when an `AsyncResource` is instantiated. | ||
|
|
||
| It is important that before/after calls are unwound | ||
| in the same order they are called. Otherwise an unrecoverable exception | ||
| will be made. | ||
|
|
||
| ```js | ||
| // AsyncEvent() is meant to be extended. Instantiating a new AsyncEvent() also | ||
| // triggers init(). If triggerId is omitted then currentId() is used. | ||
| const asyncEvent = new AsyncEvent(type[, triggerId]); | ||
| // AsyncResource() is meant to be extended. Instantiating a | ||
| // new AsyncResource() also triggers init(). If triggerId is omitted then | ||
| // currentId() is used. | ||
| const asyncResource = new AsyncResource(type[, triggerId]); | ||
|
|
||
| // Call before() hooks. | ||
| asyncEvent.emitBefore(); | ||
| asyncResource.emitBefore(); | ||
|
|
||
| // Call after() hooks. | ||
| asyncEvent.emitAfter(); | ||
| asyncResource.emitAfter(); | ||
|
|
||
| // Call destroy() hooks. | ||
| asyncEvent.emitDestroy(); | ||
| asyncResource.emitDestroy(); | ||
|
|
||
| // Return the unique id assigned to the AsyncEvent instance. | ||
| asyncEvent.asyncId(); | ||
| // Return the unique id assigned to the AsyncResource instance. | ||
| asyncResource.asyncId(); | ||
|
|
||
| // Return the trigger id for the AsyncEvent instance. | ||
| asyncEvent.triggerId(); | ||
| // Return the trigger id for the AsyncResource instance. | ||
| asyncResource.triggerId(); | ||
| ``` | ||
|
|
||
| #### `AsyncEvent(type[, triggerId])` | ||
| #### `AsyncResource(type[, triggerId])` | ||
|
|
||
| * arguments | ||
| * `type` {string} the type of ascycn event | ||
| * `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 {AsyncEvent} A reference to `asyncHook`. | ||
| * Returns {AsyncResource} A reference to `asyncHook`. | ||
|
|
||
| Example usage: | ||
|
|
||
| ```js | ||
| class DBQuery extends AsyncEvent { | ||
| class DBQuery extends AsyncResource { | ||
| constructor(db) { | ||
| this.db = db; | ||
| } | ||
|
|
@@ -459,15 +460,15 @@ class DBQuery extends AsyncEvent { | |
| } | ||
| ``` | ||
|
|
||
| #### `asyncEvent.emitBefore()` | ||
| #### `asyncResource.emitBefore()` | ||
|
|
||
| * Returns {undefined} | ||
|
|
||
| Call all `before()` hooks and let them know a new asynchronous execution | ||
| context is being entered. If nested calls to `emitBefore()` are made the stack | ||
|
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. comma after |
||
| of `id`s will be tracked and properly unwound. | ||
|
|
||
| #### `asyncEvent.emitAfter()` | ||
| #### `asyncResource.emitAfter()` | ||
|
|
||
| * Returns {undefined} | ||
|
|
||
|
|
@@ -479,7 +480,7 @@ automatically be called for all `id`'s on the stack if the error is handled by | |
| a domain or `'uncaughtException'` handler. So there is no need to guard against | ||
| this. | ||
|
|
||
| #### `asyncEvent.emitDestroy()` | ||
| #### `asyncResource.emitDestroy()` | ||
|
|
||
| * Returns {undefined} | ||
|
|
||
|
|
@@ -488,10 +489,10 @@ be thrown if it is called more than once. This **must** be manually called. If | |
| the resource is left to be collected by the GC then the `destroy()` hooks will | ||
| never be called. | ||
|
|
||
| #### `asyncEvent.asyncId()` | ||
| #### `asyncResource.asyncId()` | ||
|
|
||
| * Returns {number} the unique `id` assigned to the resource. | ||
|
|
||
| #### `asyncEvent.triggerId()` | ||
| #### `asyncResource.triggerId()` | ||
|
|
||
| * Returns {number} the same `triggerId` that is passed to `init()` hooks. | ||
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.
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.