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

session lost after bluebird.delay

Open joniba opened this issue 5 years ago • 2 comments

I'm trying to integrate cls into an existing project running both async/await and bluebird. Everything works terrific, until bluebird.delay is called, at which point the session gets lost. Example code:

var Promise = require('bluebird');
var cls = require('continuation-local-storage');
var session = cls.createNamespace('blah');

session.run(async () => {
    session.set('one', 1);
    await Promise.resolve().delay(1);
    console.log(`========== one: ${cls.getNamespace('blah').get('one')} ==========`);
})

Help would be greatly appreciated

joniba avatar Mar 15 '19 14:03 joniba

replace var cls = require('continuation-local-storage'); with var cls = require('cls-hooked');

carlisliu avatar Mar 20 '19 02:03 carlisliu

Thank you so much @carlisliu, I had the same problem with TypeORM 👍

skrosoft avatar Sep 06 '20 22:09 skrosoft