// a few side effects.
events.usingDomains = true;
+// replace tickers with domain specific implementation
+process.nextTick = process._nextDomainTick;
+process._tickCallback = process._tickDomainCallback;
+
exports.Domain = Domain;
exports.create = exports.createDomain = function(cb) {
startup.processNextTick = function() {
var _needTickCallback = process._needTickCallback;
var nextTickQueue = [];
- var usingDomains = false;
var needSpinner = true;
var inTick = false;
// needs to be accessible from cc land
process._tickDomainCallback = _tickDomainCallback;
process.nextTick = nextTick;
+ process._nextDomainTick = _nextDomainTick;
// the maximum number of times it'll process something like
// nextTick(function f(){nextTick(f)})
// no callbacks to run
if (infoBox[length] === 0)
return infoBox[index] = infoBox[depth] = 0;
- if (nextTickQueue[infoBox[length] - 1].domain)
- _tickDomainCallback();
- else
- _tickCallback();
+ process._tickCallback();
}
// run callbacks that have no domain
if (infoBox[depth] >= process.maxTickDepth)
maxTickWarn();
- var obj = { callback: callback };
- if (process.domain !== null) {
- obj.domain = process.domain;
- // user has opt'd to use domains, so override default functionality
- if (!usingDomains) {
- process._tickCallback = _tickDomainCallback;
- usingDomains = true;
- }
+ var obj = { callback: callback, domain: null };
+
+ nextTickQueue.push(obj);
+ infoBox[length]++;
+
+ if (needSpinner) {
+ _needTickCallback();
+ needSpinner = false;
}
+ }
+
+ function _nextDomainTick(callback) {
+ // on the way out, don't bother. it won't get fired anyway.
+ if (process._exiting)
+ return;
+ if (infoBox[depth] >= process.maxTickDepth)
+ maxTickWarn();
+
+ var obj = { callback: callback, domain: process.domain };
nextTickQueue.push(obj);
infoBox[length]++;
at maxTickWarn (node.js:*:*)
at process.nextTick (node.js:*:*)
at f (*test*message*max_tick_depth_trace.js:*:*)
- at _tickCallback (node.js:*:*)
+ at process._tickCallback (node.js:*:*)
at process._tickFromSpinner (node.js:*:*)
tick 0