Last active
December 21, 2015 00:48
-
-
Save tooxie/6222679 to your computer and use it in GitHub Desktop.
This file contains 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
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'); |
This file contains 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
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!'); | |
} | |
} |
This file contains 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
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