node-continuation-local-storage
node-continuation-local-storage copied to clipboard
How to deal with multiple Promise impls?
In a single project there may be
- multiple versions of Promise implementation, say
bluebird@2
,bluebird@1
- multiple packages of Promise implementation, say coexistence of
bluebird
andQ
.
All these Promise impls will be mixed together in a Promise chain and contexts can be easily lost if any of these Promise implementations are not patched.
Any better solutions other than monkey-pactch all the Promise impl found in node_modules
?
Other than patching the world, I think you can make sure to adapt all promises your application receives from libraries out of your control (e.g. using Q(unknownPromise)
or bluebird.resolve(unknownPromise)
).
That should also guarantee the CLS context is tracked in the rest of the promise chain.
Sounds feasible, but your business code will be like:
const Promise = require('bluebird');
patchPromise(Promise);
const service = {
foo: function() {
return Promise.resolve(service1.bar().then(()=> service2.koo()));
}
};
It doesn't look DRY at all.