Skip to content

Fulfillment handler called twice #364

Description

@poelstra

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions