Created
January 30, 2013 17:59
-
-
Save isaacs/4675202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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