Skip to content

Promise.join calls callback synchronously #1153

Description

@overlookmotel

Please answer the questions the best you can:

  1. What version of bluebird is the issue happening on?

v2.10.2, v3.4.1

  1. What platform and version? (For example Node.js 0.12 or Google Chrome 32)

Node v6.2.1, OS X 10.9.5

  1. 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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions