Please answer the questions the best you can:
- What version of bluebird is the issue happening on?
v2.10.2, v3.4.1
- What platform and version? (For example Node.js 0.12 or Google Chrome 32)
Node v6.2.1, OS X 10.9.5
- Did this issue happen with earlier version of bluebird?
Yes, consistent across v2.x and v3.x
Promise.join's behavior in when it calls the callback (final argument) depends on the state of the promises it's passed. If all promises are resolved, it runs the callback synchronously; but if any of the promises are pending, it runs callback async.
Promise.join(
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
function(a, b, c) {
console.log( {a: a, b: b, c: c} );
}
);
console.log('next sync statement');
outputs:
{ a: 1, b: 2, c: 3 }
next sync statement
But:
Promise.join(
Promise.resolve(1),
Promise.resolve(2).tap( function() {} ),
Promise.resolve(3),
function(a, b, c) {
console.log( {a: a, b: b, c: c} );
}
);
console.log('next sync statement');
next sync statement
{ a: 1, b: 2, c: 3 }
I'm not completely sure of the intended behavior, but I tend to think that this unpredictability isn't ideal and the callback should never be called synchronously.
Please answer the questions the best you can:
v2.10.2, v3.4.1
Node v6.2.1, OS X 10.9.5
Yes, consistent across v2.x and v3.x
Promise.join's behavior in when it calls the callback (final argument) depends on the state of the promises it's passed. If all promises are resolved, it runs the callback synchronously; but if any of the promises are pending, it runs callback async.outputs:
But:
I'm not completely sure of the intended behavior, but I tend to think that this unpredictability isn't ideal and the callback should never be called synchronously.