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

join() with rejection callback #1

Open
tomalec opened this issue May 23, 2011 · 4 comments
Open

join() with rejection callback #1

tomalec opened this issue May 23, 2011 · 4 comments

Comments

@tomalec
Copy link

tomalec commented May 23, 2011

Hi Kris, I'm noob in Promises idea, and I'm wondering how to run callback on join rejection?
Since join rejection reason is a Promise I've managed to do something like: https://gist.github.com/987205
Is there any better/cleaner way to do so?

@kriskowal
Copy link
Owner

Hey, this is the best way to observe the rejection at the moment. Unless you're reporting, you probably don't need to observe the resolution of all the rejection reasons (the Q.when(error.reasons)) — The joined callback rejects at the first opportunity, which means not all of the joined promises have been resolved, and some of them might be rejected in the future. It's also a good idea to return the result of Q.when even in callbacks, so that the promises get chained.

Other than that, I'm still looking for cleaner ways to do this pattern. It might be better for join to return a function that accepts the callback and errback, passing all the values to the callback. I don't know yet, but I'll keep thinking about it.

@csosborn
Copy link

csosborn commented Aug 3, 2011

I noticed that my code using join() works if I require('q') but fails if I require('qq'), and it seems to be related to this. Is the version of join() in q a newer approach?

I'm using this pattern:

Q.join(obj1, obj2, obj3, 
    function(a, b, c) { return a+b+c; }
).then(success, function(err) {
    // here I expect err to be the first rejection reason from left to right, as in q docs, but it isn't in qq
});

@kriskowal
Copy link
Owner

qq contains an older version of join I wrote myself, but I found Mark Miller's implementation of "all", which I used to implement "join" in "q". I should remove the version in "qq"

@csosborn
Copy link

csosborn commented Aug 4, 2011

Or if you aren't hoping to retire qq's join outright, perhaps just rename it so it doesn't mask the one from q. That way if anyone is using it they can update with a trivial rename rather than code rework.

Thanks!

@kriskowal kriskowal reopened this Aug 9, 2011
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

3 participants