Skip to content

Instantly share code, notes, and snippets.

@nickleefly
Forked from isaacs/http.js
Created November 12, 2012 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickleefly/4057311 to your computer and use it in GitHub Desktop.
Save nickleefly/4057311 to your computer and use it in GitHub Desktop.
var domain = require('domain');
var d = domain.create()
var fs = require('fs')
server = require('http').createServer(
function(req, res) {
var d2 = domain.create();
d2.add(req)
d2.add(res)
d2.run(function() {
fs.createReadStream(__filename)
.on('data', function() {
var d3 = domain.create();
d3.run(function() {
setTimeout(function() {
throw 'wooooooooo!!'
}, 100)
})
d2.add(d3)
// d3.on('error', function(er) {
// console.error('d3 caught');
// });
// back in d2
})
});
d2.on('error', function(er) {
res.on('finish', function () {
req.connection.destroy()
})
console.log('error', er, er.domain == d2);
res.statusCode = 500
res.end('oh noes!\r\n')
server.close()
})
}).listen(8000);
d.add(server);
d.on('error', function(er) {
console.error('got an error in the server',
er);
})
function tf () {
var threw = true;
try {
// lkaslkjlafaslaasdfasd
process;
threw = false;
} finally {
if (threw === true)
console.error('thrown!');
else
console.error('did not throw')
}
}
tf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment