Skip to content

Instantly share code, notes, and snippets.

@Jimbly
Last active August 29, 2015 13:57
Show Gist options
  • Save Jimbly/9379878 to your computer and use it in GitHub Desktop.
Save Jimbly/9379878 to your computer and use it in GitHub Desktop.
var domain = require('domain');
var assert = require('assert');
var DELAY = 10;
function doerr() {
var fired = false;
setTimeout(function () {
fired = true;
throw "Handled error";
}, DELAY);
setTimeout(function () {
if (!fired) {
console.log('Test failed');
}
}, DELAY + 1000);
}
function withoutDomains(do_final) {
var next;
process.on('uncaughtException', function (err) {
console.log('uncaughtException: ' + err);
next();
});
doerr();
next = function () {
doerr();
next = function () {
process.removeAllListeners('uncaughtException');
do_final();
};
};
}
function withDomains() {
var next;
function asyncError() {
var d = domain.create();
d.on('error', function (err) {
console.log('asyncError: ' + err);
d.dispose();
next();
});
d.run(doerr);
}
asyncError();
next = function () {
asyncError();
next = function () {
console.log('Test passed.');
};
};
}
withoutDomains(function () {
withDomains();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment