We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Promise.reduce()
Promise.reduce() loses CLS context with bluebird v2.
Example:
var cls = require('continuation-local-storage'); var ns = cls.createNamespace('test'); var Promise = require('bluebird'); require('cls-bluebird')(ns); ns.run(function() { ns.set('id', 1); Promise.reduce([1, 2, 3], function(total, v) { console.log('In context 1:', ns.get('id')); }, 0); }); ns.run(function() { ns.set('id', 2); Promise.reduce([1, 2, 3], function(total, v) { console.log('In context 2:', ns.get('id')); }, 0); });
Expected output is:
In context 1: 1 In context 1: 1 In context 1: 1 In context 2: 2 In context 2: 2 In context 2: 2
But in reality you get:
In context 1: 1 In context 1: 1 In context 1: 1 In context 2: 1 In context 2: 1 In context 2: 1
So CLS context is getting mixed up between the two reduce callbacks.
reduce
The text was updated successfully, but these errors were encountered:
Here's the fix:
shimmer.wrap(Promise, 'reduce', function(reduce) { return function(arr, fn, value) { return reduce.call(this, arr, ns.bind(fn), value); }; }); shimmer.wrap(Promise.prototype, 'reduce', function(reduce) { return function(fn, value) { return reduce.call(this, ns.bind(fn), value); }; });
Sorry, something went wrong.
Fixed in v2.0.0
No branches or pull requests
Promise.reduce()
loses CLS context with bluebird v2.Example:
Expected output is:
But in reality you get:
So CLS context is getting mixed up between the two
reduce
callbacks.The text was updated successfully, but these errors were encountered: