-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
async_hooks: docs and api ergonomics tweaks #15103
Conversation
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.
Code LGTM.
Semi-Rubberstamp the docs.
/cc @nodejs/async_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.
Left a few possible changes about the docs
doc/api/async_hooks.md
Outdated
|
||
In the case of Promises, the `resource` object will have `promise` property | ||
that refers to the Promise that is being initialized, and a `parentId` property | ||
that equals the `asyncId` of a parent Promise, if there is one, and | ||
that set to the `asyncId` of a parent Promise, if there is one, and |
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.
that
isn't needed anymore
doc/api/async_hooks.md
Outdated
considered public, but using the Embedder API users can provide and document | ||
their own resource objects. Such as resource object could for example contain | ||
the SQL query being executed. | ||
useful information that can vary based on the value of `type`. For instance, |
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.
maybe swap out it for resource
? was slightly unclear what it was referring to
doc/api/async_hooks.md
Outdated
*Note:* Some resources depend on garbage collection for cleanup, so if a | ||
reference is 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 |
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.
I think a comma is needed after not depend on garbage collection
doc/api/async_hooks.md
Outdated
* `type` {string} the type of ascyc event | ||
* `triggerAsyncId` {number} the ID of the execution context that created this async | ||
event | ||
* `type` {string} the type of ascyc event. If `type` is `null` or `undefined`, |
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.
ascyc --> async
doc/api/async_hooks.md
Outdated
|
||
Below is another example with additional information about the calls to | ||
Following is an example with additional information about the calls 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.
Not completely sure about this one, but should this be The following
? 😬
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.
I'm not so sure about the type
default.
lib/async_hooks.js
Outdated
// If type is null or undefined, set it by default | ||
// to the new.target.name. This avoids an error when | ||
// emitInitScript is called. | ||
if (type == null) |
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.
- This won't work with async_hooks: expose list of types #13610. /cc @refack
- If the user types
new AsyncResource()
the name will conflict with another module. - You can use
type = new.target.name
in the constructor.
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 we don't default then we should TypeError if the type isn't provided rather than the more obscure error that throws now.
throw `TypeError` if `type` is not provided or is not a string
9c2f1d5
to
def3c83
Compare
@AndreasMadsen ... ok, I've reworked this to take the approach of throwing instead of defaulting. PTAL. @refack ... please take another look also. |
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.
LGTM
We could do some behind the scenes juggling like But that could wait for a future PR. Explicit |
With the change to the error handling, this actually becomes a semver-major. @addaleax and @trevnorris ... I'd appreciate a review on this. |
@jasnell async_hooks is still experimental. Therefore this should not be semver-major. |
Yes, technically that's correct, but given that they've been around for a while now, I think it's prudent to be careful |
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.
have a couple questions, but nothing that needs to be done.
|
||
*Note*: In some cases the resource object is reused for performance reasons, | ||
it is thus not safe to use it as a key in a `WeakMap` or add properties to it. | ||
|
||
###### asynchronous context example | ||
###### Asynchronous context example |
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.
not sure of any current style, but should headers capitalize all words? doesn't matter to me either way.
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.
heck if I know. I don't think we've had much of a consistent style here.
doc/api/async_hooks.md
Outdated
`console.log()` being called. This is because binding to a port without a | ||
hostname is actually synchronous, but to maintain a completely asynchronous API | ||
the user's callback is placed in a `process.nextTick()`. | ||
hostname is a *synchronous* operation within Node.js, but to maintain a |
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.
is "within Node.js" necessary? possibly we're referring to something else, but i'm not sure what.
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.
Likely not necessary.
doc/api/async_hooks.md
Outdated
appropriate callbacks are called. To accommodate this a JavaScript API is | ||
provided. | ||
Library developers that handle their own asychronous resources performing tasks | ||
like I/O, connection pooling, or managing callback queues may use the AsyncWrap |
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.
should AsyncWrap
be placed in backticks?
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.
Yep.
@nodejs/tsc ... this needs another tsc member to review (unless folks are ok with it not being semver-major) |
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.
LGTM as semver-minor.
I prefer this to land in 8 than not have it in there.
What's the plan for moving async-hooks out of experimental?
@mcollina Let's have the discussion in #14717. I've made a comment on what I think is required #14717 (comment). |
Update docs and type checking for AsyncResource type PR-URL: #15103 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Landed in d8a0364 |
Update docs and type checking for AsyncResource type PR-URL: nodejs/node#15103 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Update docs and type checking for AsyncResource type PR-URL: #15103 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Update docs and type checking for AsyncResource type PR-URL: nodejs/node#15103 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Some doc improvements and a AsyncResource constructor ergonomics tweak...
Previously, if
type
was passed to theAsyncResource
class asnull
orundefined
,an error would be thrown. With this,
type
defaults tonew.target.name
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
async_hooks