-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
async_hooks: docs and api ergonomics tweaks #15103
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
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
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
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
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
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
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
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.
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