Created
July 4, 2012 11:21
-
-
Save shigeki/3046839 to your computer and use it in GitHub Desktop.
Domain Stack Sample
This file contains hidden or 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
// domain stack sample | |
var domain = require('domain'); | |
var d1 = domain.create(); | |
var d2 = domain.create(); | |
var d3 = domain.create(); | |
d1.on('error', function(err) { | |
console.log('d1:', err.message); | |
}); | |
d2.on('error', function(err) { | |
console.log('d2:', err.message); | |
}); | |
d3.on('error', function(err) { | |
console.log('d3:', err.message); | |
}); | |
function foo(arg) { | |
if (arg === 2) { | |
throw new Error('d2 error'); | |
} | |
d3.run(function() { | |
throw new Error('d3 error'); | |
}); | |
} | |
function hoge(arg) { | |
if (arg === 1) { | |
throw new Error('d1 error'); | |
} | |
d2.run(function() { | |
foo(arg); | |
}); | |
} | |
d1.run(function() { | |
hoge(+process.argv[2]); | |
}); |
This file contains hidden or 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
> node domain_stack.js 1 | |
d1: d1 error | |
> node domain_stack.js 2 | |
d2: d2 error | |
> node domain_stack.js 3 | |
d3: d3 error | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment