Skip to content
Closed
Changes from 1 commit
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
Next Next commit
Memoize will now play nicely with Nodejs domains.
  • Loading branch information
owenallenaz committed Jan 4, 2016
commit c92bc2c7422f939c7f54c66e49ff320a4ca32e93
8 changes: 7 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@
return iterator(value, callback);
};
}

// binds a callback to a domain, necessary in Node if a callback may be resolved in a different context, such as with memoize()
function bindToCurrentDomain(callback) {
if (typeof process !== "object" || process.domain == null || callback == null) return callback;
return process.domain.bind(callback);
}

//// exported async module functions ////

Expand Down Expand Up @@ -1095,7 +1101,7 @@
});
}
else if (key in queues) {
queues[key].push(callback);
queues[key].push(bindToCurrentDomain(callback));
}
else {
queues[key] = [callback];
Expand Down