Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Async.prototype.haveItemsQueued = function Async$haveItemsQueued() {
Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) {
ASSERT(typeof fn === "function");
ASSERT(arguments.length === 3);
if ( process != null && process.domain != null &&
fn.domain == null &&
typeof process.domain.bind === "function" ) {
fn = process.domain.bind(fn);
}
this._lateBuffer.push(fn, receiver, arg);
this._queueTick();
};
Expand All @@ -35,6 +40,11 @@ Async.prototype.invoke = function Async$invoke(fn, receiver, arg) {
ASSERT(typeof fn === "function");
ASSERT(arguments.length === 3);
var functionBuffer = this._functionBuffer;
if ( process != null && process.domain != null &&
fn.domain == null &&
typeof process.domain.bind === "function" ) {
fn = process.domain.bind(fn);
}
functionBuffer.push(fn, receiver, arg);
this._length = functionBuffer.length();
this._queueTick();
Expand Down Expand Up @@ -63,7 +73,12 @@ Async.prototype._consumeLateBuffer = function Async$_consumeLateBuffer() {
var res = tryCatch1(fn, receiver, arg);
if (res === errorObj) {
this._queueTick();
throw res.e;
if (fn.domain != null) {
fn.domain.emit("error", res.e);
}
else {
throw res.e;
}
}
}
};
Expand Down