-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: expand on promises and async_hooks #18540
Conversation
doc/api/async_hooks.md
Outdated
``` | ||
|
||
Observe that the `then` callback claims to have executed in the context of the | ||
outer scope even though there was asynchronous hop involved. Also note that the |
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.
an asynchronous hop?
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.
Done.
doc/api/async_hooks.md
Outdated
@@ -509,6 +509,9 @@ const server = net.createServer(function onConnection(conn) { | |||
}); | |||
``` | |||
|
|||
Note that promise contexts may not get precise execuationAsyncIds by default. | |||
See the section on [promise execution tracking][#promise_execution_tracking]. |
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.
Link doesn't seem to work.
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.
Also execuationAsyncIds -> executionAsyncIds in the previous line.
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.
It seems this should be [promise execution tracking][]
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.
Thanks. Fixed.
doc/api/async_hooks.md
Outdated
|
||
Observe that the `then` callback claims to have executed in the context of the | ||
outer scope even though there was asynchronous hop involved. Also note that the | ||
tiggerAsyncId value is 0, which means that we are missing context about the |
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.
🐯
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.
Fixed all the 🐯s.
doc/api/async_hooks.md
Outdated
promise with asyncId 7. This promise was triggered by async resource 6. | ||
|
||
Another subtlety with promises is that `before` and `after` callbacks are run | ||
only on chained promises. That means promises not created by `then` will not |
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 is because callbacks passed to then
(or catch
; I think you should add that) are added to the Promise micro-task queue, right? Maybe mention that callbacks passed to then
are different than the ones passed to the Promise
constructor because they will not run synchronously from where then
is called.
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.
Added mention of catch
callbacks. The reason is actually due to the implementation choice in PromiseHooks. It was entirely possible for V8 to implement things in a way that promises created by new
or Promise.resolve()
etc. would get before
/ after
callbacks too. For the tradeoffs used, see this doc.
doc/api/async_hooks.md
Outdated
## Promise execution tracking | ||
|
||
By default, promise executions are not assigned asyncIds due to the relatively | ||
expensive nature of the [promise instrospection API][PromiseHooks] provided by |
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.
instrospection -> introspection
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.
Done.
doc/api/async_hooks.md
Outdated
By default, promise executions are not assigned asyncIds due to the relatively | ||
expensive nature of the [promise instrospection API][PromiseHooks] provided by | ||
V8. This means that programs using promises or `async`/`await` will not get | ||
correct execution and tigger ids for promise callback contexts by default. |
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.
tigger -> trigger
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.
Done.
doc/api/async_hooks.md
Outdated
@@ -655,3 +709,5 @@ constructor. | |||
[`destroy` callback]: #async_hooks_destroy_asyncid | |||
[`init` callback]: #async_hooks_init_asyncid_type_triggerasyncid_resource | |||
[Hook Callbacks]: #async_hooks_hook_callbacks | |||
[PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk | |||
[promise execution tracking]: #promise_execution_tracking |
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.
It seems this will be #async_hooks_promise_execution_tracking
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.
Thanks, done.
AsyncHooks have a few subtleties with being able to track promises. This commit adds a section to the docs that explains things the issues. PR-URL: nodejs#18540 Fixes: nodejs#18520 Reviewed-By: James M Snell <[email protected]>
Thanks. Landed in d4b605b. |
AsyncHooks have a few subtleties with being able to track promises. This commit adds a section to the docs that explains things the issues. PR-URL: #18540 Fixes: #18520 Reviewed-By: James M Snell <[email protected]>
AsyncHooks have a few subtleties with being able to track promises. This commit adds a section to the docs that explains things the issues. PR-URL: #18540 Fixes: #18520 Reviewed-By: James M Snell <[email protected]>
AsyncHooks have a few subtleties with being able to track promises. This commit adds a section to the docs that explains things the issues. PR-URL: #18540 Fixes: #18520 Reviewed-By: James M Snell <[email protected]>
AsyncHooks have a few subtleties with being able to track promises. This commit adds a section to the docs that explains things the issues. PR-URL: #18540 Fixes: #18520 Reviewed-By: James M Snell <[email protected]>
AsyncHooks have a few subtleties with being able to track promises. This commit adds a section to the docs that explains things the issues. PR-URL: nodejs#18540 Fixes: nodejs#18520 Reviewed-By: James M Snell <[email protected]>
AsyncHooks have a few subtleties with being able to track promises.
This commit adds a section to the docs that explains things the issues.
Fixes: #18520
Checklist
Affected core subsystem(s)
doc:async_hooks
/cc @nodejs/async_hooks @nodejs/diagnostics
EDIT: CI: https://ci.nodejs.org/job/node-test-pull-request-lite/146/