Skip to content

Instantly share code, notes, and snippets.

Created July 4, 2012 22:36
Show Gist options
  • Select an option

  • Save anonymous/3049876 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/3049876 to your computer and use it in GitHub Desktop.
(function (exports, require, module, __filename, __dirname) { // domain stack sample
var fs = require('fs'), domain = require('domain');
(function(i) {
var d = domain.create(), nm = 'd' + i;
d.run(acceptFn(nm, d));
})(0);
function acceptFn(name, d) {
var timer = null;
d.on('error', function(err) {
clearTimeout(timer);
console.log(name + ':', err.message);
});
return function() {
timer = setTimeout(function() {
throw new Error(name + ' Timeout');
}, 300);
setTimeout(function() {
fs.readFile('aaa', hoge);
clearTimeout(timer);
}, 360);
};
}
function hoge(err) {
if(err)
throw err;
a.hoge;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment