New issue

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

Fulfillment handler called twice #364

Closed
poelstra opened this Issue Oct 24, 2014 · 2 comments

Comments

Projects
None yet
1 participant
@poelstra

poelstra commented Oct 24, 2014

Using a specific order of attaching callbacks and resolving, one of the fulfillment handlers is called twice for the same promise.

Given the following NodeJS test program:

var Promise = require("bluebird");

var calls = 0;
var def = defer();

def.promise.then(function() {
    console.log("1");
});
def.resolve();
def.promise.then(function() {
    console.log("2");
    calls++;
    if (calls > 1) {
        console.log("BLUEBIRD ERROR");
    }
}).then(function() {
    console.log("3");
});

function defer() {
    var resolve, reject;
    var promise = new Promise(function() {
        resolve = arguments[0];
        reject = arguments[1];
    });
    return {
        resolve: resolve,
        reject: reject,
        promise: promise
    };
}

I'd expect the output to be:

1
2
3

but this produces (using Bluebird 2.3.6):

1
2
3
2
BLUEBIRD ERROR

Moving the .resolve() to before the first .then() makes the error disappear.

@poelstra

This comment has been minimized.

Show comment
Hide comment
@poelstra

poelstra Oct 25, 2014

Thnx for the fast fix!

poelstra commented Oct 25, 2014

Thnx for the fast fix!

@poelstra

This comment has been minimized.

Show comment
Hide comment
@poelstra

poelstra Oct 28, 2014

I saw you've bumped the package version on Github, but it's not yet available on NPM.
Could you please publish it?

poelstra commented Oct 28, 2014

I saw you've bumped the package version on Github, but it's not yet available on NPM.
Could you please publish it?

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