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

all() in promised-io 0.3.0 cannot handle more than one rejected promise #30

Open
calmh opened this issue Mar 26, 2012 · 0 comments
Open

Comments

@calmh
Copy link
Contributor

calmh commented Mar 26, 2012

When you try to do a all() around several promises and more than one of them get rejected, it fails with an "Error: This deferred has already been resolved". This seems to be due to the error callback being called immediately when the first rejection occurs, then again on the next rejected. It would perhaps be preferable to wait for all promises to either succeed or reject, and then call the appropriate callback? Or is there an obvious workaround/user error here? Example to reproduce:

var q = require('promised-io');

function fail(delay) {
    var d = q.defer();
    setTimeout(function () {
        d.reject(new Error('foo'));
    }, delay);
    return d.promise;
}

q.all(fail(250), fail(500)).then(function () {
    console.log("success");
}, function () {
    console.log("error");
});

Result:

% node ntest.js
error

timers.js:96
            if (!process.listeners('uncaughtException').length) throw e;
                                                                      ^
Error: This deferred has already been resolved
    at notifyAll (/Users/jb/src/zpoller/node_modules/promised-io/promise.js:164:10)
    at /Users/jb/src/zpoller/node_modules/promised-io/promise.js:229:3
    at notify (/Users/jb/src/zpoller/node_modules/promised-io/promise.js:199:22)
    at notifyAll (/Users/jb/src/zpoller/node_modules/promised-io/promise.js:179:5)
    at [object Object].<anonymous> (/Users/jb/src/zpoller/node_modules/promised-io/promise.js:229:3)
    at Object._onTimeout (/Users/jb/src/zpoller/ntest.js:6:11)
    at Timer.ontimeout (timers.js:94:19)
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