-
Notifications
You must be signed in to change notification settings - Fork 78
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
Adding doc describing "async context" in terms of "continuations" #197
Adding doc describing "async context" in terms of "continuations" #197
Conversation
//cc @nodejs/diagnostics, @mrkmarron, @ofrobots, @kjin |
@kjin - thanks for comments, all makes sense. I'm going off the grid until next wed - will incorporate your feedback then. |
cc @domenic |
Very good work. In https://github.com/mike-kaufman/diagnostics/blob/11206a47094846bc0b1027ab82c7bd0fa4f04d87/async-context/README.md#continuation-local-storage I would use a private symbol to store the cls. I think the example there of walking the "linking context" is very expensive. Moreover, I'm not necessarily convinced it works in the case of await. Consider the following: async function f2 () {
await something()
// consider this point B
}
async function f1 () {
await f2()
// consider this point A
} The problem with walking the context during get() (as in the example in the document), is that whatever we add in point B will not be included in point A. I believe the users would expect the two continuations to be linked, but they are not. This is because of how async await is specified (I'm not the best person to explain why, cc @bmeurer), and the promise f2() and the result of await are parallel continuations. I do not think it is possible to handle CLS without a |
Great stuff. Can we define what is what I call a "continuation loss" meaning for some reason |
@vdeturckheim - can you provide some examples of where/why this would happen. Ideally, this is pathological behavior. i.e., we provide clear & crisp definitions, and the implementation returns "the right thing" based on these definitions. This is the "Async Call Graph". Now, it's possible that different applications want to traverse the graph in different ways, but I wouldn't call this a "continuation loss". |
@mike-kaufman I agree this is a case that should not happen. |
@mcollina - thanks for the feedback. Please keep comments like this coming! Sorry for length of post below. Happy to get on phone to clarify anything.
I'll look into the implementation of generators and async/await in more detail to see check my assumptions here. For now, I'll break your example down into it's functionally equivalent promise-based implementation, since I think that makes the async boundaries more clear: function f2 () {
return somethingThatReturnsAPromise()
.then(function f3() { // line 3
// consider this point B
});
}
function f1 () {
return f2()
.then(function f4() { // line 10
// consider this point A
});
} Given definitions above, we have the following stack at the time that
And we have the following stack at the time
And we have the following stack at the time
Note that all of the above are executing within the same
Now, to address your questions:
I've been thinking a bit about how dynamically prescribe traversal paths through the graph for specific functionality. (e.g., how do we choose the "correct path" through the graph to do CLS"?) I think the answer here is to allow dynamic labels over the edges such that a "CLS iterator" can choose the path of edges labeled "CLS" as it traverses. This needs to be communicated in more detail, but I think it nicely accomodates the expected behavior you suggest. |
I think besides linking continuations we have to think also about combining them - and decide which link context is the right one (or both?).
Here we have two resolvers for the returned promise. In this sample the link context of |
…this fits into ECMAScript specification.
@gireeshpunathil I think we might as well land it and then we can update if needed. |
Maybe merge and add a note at the top that the doc needs editing? |
+1 |
Add a doc on async_context in terms of continuations PR-URL: #197 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
landed in bdcfe0e |
See here for a rendered view of the markdown.
This is a refinement of the work we've been doing in http://github.com/mike-kaufman/async-context-definition/. I would really appreciate any feedback people have on the terminology, concepts, correctness, or the flow of the document - my intent here is this is easily explainable to a broad section of JS programmers.