-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Support for node js domains #113
Comments
If you want to use domains you need to do |
It's also worth noting that domains are deprecated (https://nodejs.org/api/domain.html#domain_domain) |
Yes, that too. I never understood why anyone thought they were a good idea. I guess it was just people who didn't understand promises. |
I am not using domains for error bubbling. I am aware that domains will soon be fully deprecated and will be replaced by some other API but for now my use case needs node.js domains. In java there is a concept called thread local which helps to define variables in the context of that thread but in node we do not have anything like that but domains. Use Case:
Solution: Create domain in the context of request
Now with the use of process.domain, I will be able to access 'data' bound to above created domain anywhere
Similar use case has been discussed here: |
You can easily implement this yourself on top of promises via something like: var Promise = require('promise');
var originalThen = Promise.prototype.then;
Promise.prototype.then = function (cb, eb) {
if (typeof cb === 'function') {
// bind cb to the current domain
}
if (typeof eb === 'function') {
// bind eb to the current domain
}
return originalThen.call(this, cb, eb);
}; We're not going to provide it by default because it represents a huge performance hit. |
promise.js breaks node js domains.
The text was updated successfully, but these errors were encountered: