-
Notifications
You must be signed in to change notification settings - Fork 396
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
Binding context to promise chain #498
Comments
Hi, First of all, never use Other than that, it seems to me that you are trying to use Promises as a context-aware task runner. It may not be a good fit, because of two reasons:
You should typically inject loggers into your logic. A handy library that can help you manage and enrich logger state is bunyan, which allows "hierarchical" loggers. One combination with |
Thank you for your comment. Maybe extending Promise prototype with new methods is bad idea. My initial thoughts were as following. The chain of promises constitutes some asynchronous 'task'. Promises wait on each other as long as they are returned from functions. When the last promise is resolved the task finishes. Why not use this promise machinery to attach some context, so the group of related asynchronous operations could be treated together. The main purpose here is context aware logging. It would be useful to have some hooks provided by the library. What I want to have is something like node domains feature ( https://nodejs.org/api/domain.html ). The API doesn't have to be the extension of var promise = db.cal('sql');
var log = getLoggingFromExecutionContext(promise);
log.debug('fetching data from db'); I have previously looked at bunyan, but I didn't find a way to group related asynchronous operations together. I will take a look once more at hierarchical logging. |
Hi!
I want to bind some context to promise chain for the purpose of context aware logging. For this my idea is to extend promise API. Here is an example:
I would expect to see something like this in the log output:
My idea was to extend
Promise
along following lines:At first I thought that
when/monitor/PromiseMonitor
would be a good start. But after playing with it for some time, I am a bit confused. To me it appears that it doesn't track context properly. Here is an example:Here I expect that p2 runs within the context of p1. However, the traceback doesn't give any insights on this:
So my question is: would
PromiseMonitor
be a good example to implement context binding to chain of promises?Is it feasible at all to extend
Promise
this way?Thank you in advance for any suggestions.
The text was updated successfully, but these errors were encountered: