othiym23 / node-continuation-local-storage

implementation of https://github.com/joyent/node/issues/5243
BSD 2-Clause "Simplified" License
1.13k stars 207 forks source link

session lost after bluebird.delay #140

Open joniba opened 5 years ago

joniba commented 5 years ago

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

carlisliu commented 5 years ago

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

skrosoft commented 4 years ago

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