async_hooks: docs and api ergonomics tweaks#15103
async_hooks: docs and api ergonomics tweaks#15103jasnell wants to merge 5 commits intonodejs:masterfrom
Conversation
refack
left a comment
There was a problem hiding this comment.
Code LGTM.
Semi-Rubberstamp the docs.
|
/cc @nodejs/async_hooks |
maclover7
left a comment
There was a problem hiding this comment.
Left a few possible changes about the docs
doc/api/async_hooks.md
Outdated
There was a problem hiding this comment.
that isn't needed anymore
doc/api/async_hooks.md
Outdated
There was a problem hiding this comment.
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.
I think a comma is needed after not depend on garbage collection
doc/api/async_hooks.md
Outdated
doc/api/async_hooks.md
Outdated
There was a problem hiding this comment.
Not completely sure about this one, but should this be The following? 😬
AndreasMadsen
left a comment
There was a problem hiding this comment.
I'm not so sure about the type default.
lib/async_hooks.js
Outdated
There was a problem hiding this comment.
- 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.namein the constructor.
There was a problem hiding this comment.
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. |
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 |
trevnorris
left a comment
There was a problem hiding this comment.
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.
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.
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.
is "within Node.js" necessary? possibly we're referring to something else, but i'm not sure what.
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.
should AsyncWrap be placed in backticks?
|
@nodejs/tsc ... this needs another tsc member to review (unless folks are ok with it not being semver-major) |
mcollina
left a comment
There was a problem hiding this comment.
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 <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
|
Landed in d8a0364 |
Update docs and type checking for AsyncResource type PR-URL: nodejs/node#15103 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Update docs and type checking for AsyncResource type PR-URL: #15103 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Update docs and type checking for AsyncResource type PR-URL: nodejs/node#15103 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Some doc improvements and a AsyncResource constructor ergonomics tweak...
Previously, if
typewas passed to theAsyncResourceclass asnullorundefined,an error would be thrown. With this,
typedefaults tonew.target.name.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
async_hooks