Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

wip

  • Loading branch information...
ry committed Sep 5, 2011
1 parent cf5d1ba commit 74c6de1bbfdf2bcb5ec5c9fef1caa262b70ea1dc
Showing with 52 additions and 8 deletions.
  1. +21 −1 lib/domain.js
  2. +11 −5 lib/timers_uv.js
  3. +6 −1 src/node.js
  4. +14 −1 test/simple/test-domains.js
@@ -41,6 +41,19 @@ Domain.prototype.enter = function() {
};


Domain.prototype.kill = function() {
for (var i = 0; i < this.handles.length; i++) {
console.error("kill " + this.handles[i]);
if (this.handles[i].close) {
this.handles[i].close();
} else {
this.handles[i].oncomplete = null;
}
}
this.handles = [];
};


Domain.prototype.exit = function() {
assert.ok(currentDomain == this);
currentDomain = null;
@@ -55,7 +68,14 @@ exports.pollNewDomains = function() {
var d;
while ((d = createQueue.shift())) {
d.enter();
d.cb(d.arg);

try {
d.cb(d.arg);
} catch (e) {
d.emit('error', e);
d.kill();
}

d.cb = null;
d.arg = null;
d.exit();
@@ -31,6 +31,12 @@ if (process.env.NODE_DEBUG && /timer/.test(process.env.NODE_DEBUG)) {
}


function closeTimer(t) {
t.close();
require('domain').remove(t);
}


// IDLE TIMEOUTS
//
// Because often many sockets will have the same idle timeout we will not
@@ -89,7 +95,7 @@ function insert(item, msecs) {

debug(msecs + ' list empty');
assert(L.isEmpty(list));
list.close();
closeTimer(list);
delete lists[msecs];
};
}
@@ -107,7 +113,7 @@ var unenroll = exports.unenroll = function(item) {
debug('unenroll');
if (list && L.isEmpty(list)) {
debug('unenroll: list empty');
list.close();
closeTimer(list);
delete lists[item._idleTimeout];
}
};
@@ -158,7 +164,7 @@ exports.setTimeout = function(callback, after) {
args = Array.prototype.slice.call(arguments, 2);
timer._onTimeout = function() {
callback.apply(timer, args);
timer.close();
closeTimer(timer);
}

timer.start(0, 0);
@@ -196,7 +202,7 @@ exports.clearTimeout = function(timer) {
if (timer && (timer.ontimeout || timer._onTimeout)) {
timer.ontimeout = timer._onTimeout = null;
if (timer instanceof Timer) {
timer.close(); // for after === 0
closeTimer(timer); // for after === 0
} else {
exports.unenroll(timer);
}
@@ -221,6 +227,6 @@ exports.setInterval = function(callback, repeat) {
exports.clearInterval = function(timer) {
if (timer instanceof Timer) {
timer.ontimeout = null;
timer.close();
closeTimer(timer);
}
};
@@ -521,7 +521,12 @@
domain.enter();
}

obj[method](arg0, arg1, arg2, arg3);
try {
obj[method](arg0, arg1, arg2, arg3);
} catch (e) {
domain.emit('error', e);
domain.kill();
}

if (domain) {
domain.exit();
@@ -23,15 +23,28 @@ var common = require('../common');
var assert = require('assert');
var domain = require('domain');

var timerCalled = false;

console.log("default domain");

var d = domain.create({ hello: "world" }, function(a) {
console.log("inside the domain");
assert.deepEqual(a, { hello: "world" });

setTimeout(function() {
timerCalled = true;
}, 1000);

throw new Error("synthetic error");
});


d.on("exit", function() {
d.on("error", function(e) {
assert.equal(e.message, "synthetic error");
console.log("domain exited");
});


process.on('exit', function() {
assert.equal(false, timerCalled);
});

0 comments on commit 74c6de1

Please sign in to comment.
You can’t perform that action at this time.