Skip to content

Instantly share code, notes, and snippets.

@tooxie
Last active December 21, 2015 00:48
Show Gist options
  • Save tooxie/6222679 to your computer and use it in GitHub Desktop.
Save tooxie/6222679 to your computer and use it in GitHub Desktop.
var http = require('http');
var rid = 0;
var uuid;
var server = http.createServer(function(req, res) {
var domain = require('domain');
var reqd = domain.create();
var uuid = require('node-uuid').v1();
rid += 1;
console.log('Request ID: ' + rid);
reqd.uuid = uuid;
reqd.run(function() {
setTimeout(function() {
require('./test1')(uuid);
}, Math.random() * 5000);
});
res.end(uuid + '\n');
});
server.listen(1234);
console.log('Listening on port 1234');
var t2 = require('./test2')();
module.exports = function(uuid) {
process.nextTick(function() {
require('./test2')(uuid);
})
if (uuid !== process.domain.uuid) {
throw new Error('UUID does not match!');
}
}
module.exports = function(uuid) {
if (typeof(uuid) !== 'undefined') {
if (uuid !== process.domain.uuid) {
throw new Error('UUID does not match!');
}
}
return process.domain.uuid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment