node-continuation-local-storage
node-continuation-local-storage copied to clipboard
bindEmitter does not work?
The code below uses bindEmitter
to bind the response object to the current context.
So onfinish
must keep the context, right?
// bind
process.namespaces.app.bindEmitter(this.res);
// plan onfinish in the future
this.res.once('finish', onfinish);
var mark = Math.random();
console.log(mark, process.namespaces.app.get('requestId'));
// onfinish will trigger later, but in current context?
function onfinish(event) {
console.log(mark, process.namespaces.app.get('requestId'));
}
For same mark
, the requestId
must be same?
I'm asking, because it's not.
Did you run all of the above within process.namespaces.app.run()
?
i.e.:
process.namespaces.app.run( function() {
process.namespaces.app.set( 'requestId', Math.random() );
process.namespaces.app.bindEmitter(this.res);
this.res.once('finish', onfinish);
console.log( process.namespaces.app.get('requestId') );
} );
function onfinish(event) {
console.log( process.namespaces.app.get('requestId') );
}
If so, the two requestId
should be the same as each other.
Are they not?