node-continuation-local-storage icon indicating copy to clipboard operation
node-continuation-local-storage copied to clipboard

bindEmitter does not work?

Open iliakan opened this issue 9 years ago • 1 comments

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.

iliakan avatar May 14 '15 19:05 iliakan

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?

overlookmotel avatar Jun 18 '16 23:06 overlookmotel