-
Notifications
You must be signed in to change notification settings - Fork 22
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
Can this be modeled on top of async hooks #41
Comments
I believe that async_hooks is not enough by itself, because of issues with userspace queueing. Essentially, if I have code like the following: // Async context 1
function foo() {
doAsyncThing("data", function () { console.log('Called back eventually')})
}
// Async context 2
function bar() {
doAsyncThing("more data", function () { console.log('called back after starting in a different context');})
}
function doAsyncThing() {
//...
manager.jobs.push({data, callback});
//...
}
// Elsewhere, asynchronously
manager.onFreeWorker = function () {
worker.jobs = this.jobs;
this.jobs = [];
worker.work().then((completedJobs) => {
for (job of completedJobs) {
job.callback();
}
}
} What context are the callbacks invoked in? There are at least 3 different asynchronous contexts here (suppose the first 2 are different HTTP requests coming in, and the worker is communicating the jobs with an out-of-process worker like a database). My understanding of async hooks would let you associate a single stack of calls together, for example the promises in |
I wasn't even talking about the async tracking, more about the data being emitted / the "diagnostics event bus". E.g. creating an The userland callback queue can be implemented using the embedder API of async hooks so the context tracking shouldn't be an issue for properly instrumented libraries in node 8+. |
Things like asynchronous operations at the very least could be expressed as (virtual) async resources. An interesting question would be if this is sufficient to express something like a "diagnostics channel" by filtering for specific async_hooks resources.
The text was updated successfully, but these errors were encountered: