Skip to content
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
Closed

Fulfillment handler called twice #364

poelstra opened this issue Oct 24, 2014 · 2 comments

Comments

@poelstra
Copy link

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
Copy link
Author

Thnx for the fast fix!

@poelstra
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant