-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix case where pre-domain nextTick executing post-domain callbacks resulted in domains being ignored #152
Conversation
Nice trick! an additional check should be added for those who are using a browser, other than that - looks promising :) |
oh yes, of course, silly me! |
Hmm, do you all prefer / is there a reason for, the whole typeof n !== 'undefined' && n !== null thing? I can repush with that variation, though it's getting a tad wordy. |
Ah, line too long for jshint |
The checks should be rearranged to optimize for the case where domains are not in use: Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) {
ASSERT(typeof fn === "function");
ASSERT(arguments.length === 3);
if (process !== void 0 &&
process.domain != null &&
!fn.domain) {
fn = process.domain.bind(fn);
}
this._lateBuffer.push(fn, receiver, arg);
this._queueTick();
}; |
I've refactored it for that and for more complete duck-typing. |
I cannot get this test to pass: "use strict";
var assert = require("assert");
var Promise = require("../../js/debug/bluebird.js");
var isNodeJS = typeof process !== "undefined" &&
typeof process.execPath === "string";
if (isNodeJS) {
describe("domain", function(){
specify("gh-148", function(done) {
Promise.onPossiblyUnhandledRejection(function(error,promise) {
throw error
});
var called = false;
var e = new Error();
Promise.resolve(23).then(function(){called = true});
require('domain').create()
.on('error', function(E) {
assert.equals(e, E);
assert(called);
done();
})
.run(function() {
var P = new Promise(function(resolve,reject){ reject(e) });
});
});
});
} To run the test place it in a file like |
Hmm, interesting… seems to be some interaction with mocha, as the following prints two "oks":
|
I'll dig further in a little bit |
…sulted in domains being ignored
Ok, because the wrapper code that's rethrowing the error isn't in a domain, we need to do domain stuff ourselves instead of rethrowing if the function was bound to a domain. Also, change |
Commited in 134c396 Thank you |
Fixes #148
Does not seem to have a measurable impact on benchmarks:
https://docs.google.com/spreadsheet/ccc?key=0AnFpRHqZj2TQdExOeWpyVjBGd3IyRUM0cXhVYjMwTHc&usp=sharing