Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cls with library using bluebird (knex) #16

Open
froxCZ opened this issue Nov 6, 2017 · 2 comments
Open

Cls with library using bluebird (knex) #16

froxCZ opened this issue Nov 6, 2017 · 2 comments

Comments

@froxCZ
Copy link

froxCZ commented Nov 6, 2017

Hey guys,
thanks a lot for this lib, I managed to get it running on node 8.6.0 with express and async/await. However, I would like to ask if it is possible to use it with other library that is using Bluebird promises - knexjs.org. My ultimate goal is to wrap knex.transaction with my own function that is going to set the transaction to namespace so the transaction can be accessed from other places.

I tried something with cls-bluebird or using ns.run or ns.bind without any success. It fails on Unhandled rejection Error: No context available. ns.run() or ns.bind() must be called first.. Accessing the namespace out of knex.transaction() works fine.

Thanks for any kind of help!

@Jeff-Lewis
Copy link
Owner

@froxCZ Sorry for not commenting earlier. I am eager to use cls-hooked with Bluebird as well, natively that is, without monkey patching. There's been work to add AsyncResource to Bluebird which would make Bluebird compatible with async_hooks and cls-hooked, although it has somewhat stalled because of its performance scare. (IMHO, I'd take a 10x slower node with reliable cls anyday...)

Alternatively, you can try cls-bluebird which has very good test test coverage, although you can't use async/await with it as async/await uses native promises.

@mrmurphy
Copy link

mrmurphy commented Nov 7, 2018

Hi! I'm just doing research about which approach is going to be most reliable, cls-hooked, or the old style of continuation-local-storage? I was specifically looking around for mentions cls-hooked of having to wrap a bunch of 3rd party modules in order to keep the context around. This is the only issue I could find that mentions something like that.

Does CLS-hooked work only with native promises? Will I have to wrap any library that uses a non-native promise implementation?

I'm guessing I'd just run my server, look at my logs, and see which logs are missing the request ID. Then I'd figure out which library to wrap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants