Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created January 30, 2013 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/4675202 to your computer and use it in GitHub Desktop.
Save isaacs/4675202 to your computer and use it in GitHub Desktop.
diff --git a/src/node.js b/src/node.js
index 9fc68e4..39830d2 100644
--- a/src/node.js
+++ b/src/node.js
@@ -417,10 +417,10 @@
while (nextTickIndex < nextTickLength) {
var tock = nextTickQueue[nextTickIndex++];
var callback = tock.callback;
- if (tock.domain) {
- if (tock.domain._disposed) continue;
- tock.domain.enter();
- }
+
+ if (tock.domain && tock.domain._disposed) continue;
+ enterDomain(tock.domain);
+
var threw = true;
try {
callback();
@@ -430,9 +430,8 @@
// so we can't clear the tickDepth at this point.
if (threw) tickDone(tickDepth);
}
- if (tock.domain) {
- tock.domain.exit();
- }
+
+ exitDomain(tock.domain);
}
nextTickQueue.splice(0, nextTickIndex);
nextTickIndex = 0;
@@ -444,6 +443,16 @@
tickDone();
};
+ function enterDomain(domain) {
+ if (domain)
+ domain.enter();
+ }
+
+ function exitDomain(domain) {
+ if (domain)
+ domain.exit();
+ }
+
process.nextTick = function(callback) {
// on the way out, don't bother.
// it won't get fired anyway.
@@ -452,12 +461,14 @@
if (tickDepth >= process.maxTickDepth)
maxTickWarn();
- var tock = { callback: callback };
- if (process.domain) tock.domain = process.domain;
- nextTickQueue.push(tock);
- if (nextTickQueue.length) {
+ var tock = {
+ callback: callback,
+ domain: process.domain || false
+ };
+ if (nextTickQueue.length === 0) {
process._needTickCallback();
}
+ nextTickQueue.push(tock);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment