-
-
Save dazld/6414160 to your computer and use it in GitHub Desktop.
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
var local = require('./namespace-module'); | |
var http = require('http'); | |
var uuid = require('uuid').v4; | |
http.createServer(function(req, res) { | |
req._id = uuid(); | |
local.run(function() { | |
local.set('id', req._id); | |
next(req, res); | |
}); | |
}).listen(3030); | |
function next(req, res) { | |
process.nextTick(function() { | |
var id = local.get('id'); | |
if (id === req._id) { | |
console.log(id); | |
} else { | |
throw new Error(id + ' !== ' + req._id); | |
} | |
res.end(''); | |
}); | |
} | |
console.log('* Listening on http://127.0.0.1:3030'); |
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
var cls = require('continuation-local-storage-glue'); | |
var ns = cls.getNamespace('nsApp'); | |
if(!ns) ns = cls.createNamespace('nsApp'); | |
module.exports = ns; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment