Open RobinQu opened 8 years ago
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.
In a single project there may be
bluebird@2
,bluebird@1
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
?