-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add allSettled to RSVP #113
Conversation
+1 |
@domenic: Why allSettled vs allResolved? I'm not sure if the reasoning in kriskowal/q#257 is relevant to RSVP, I was unable to follow that thread and the Promises/A+ spec doesn't mention "settled" promises. I also had a quick discussion with @twokul regarding the proposed API. What if allSettled fulfilled with an array of values if all the dependent promises fulfill, but reject with with an array of snapshots in the event that any of the dependent promises reject? This would lead to less code in the fulfilled case. |
@mmun https://github.com/domenic/promises-unwrapping/blob/master/states-and-fates.md
How do you propose to distinguish the case of |
@domenic The first would fulfill with Thanks for the link. I really appreciate that you've taken the time to really nail down the terminology! |
No, |
Gotcha. Thanks. |
i'll be doing a RSVP push this weekend. If u can rebase this that would be great. @domenic this still look good? |
@stefanpenner let me know if it needs further updating! |
@@ -2,6 +2,7 @@ import { EventTarget } from "./rsvp/events"; | |||
import { Promise } from "./rsvp/promise"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol this file is crying for some export * from "x"
love. I wonder if es6-module-transpiler supports that yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can update it on Jan 2nd -- believe it or not, that's the next time I'll be at a keyboard! Sorry about the delay, will get to this then if you can wait that long.
|
@stefanpenner nope, it's still |
@decasia no worries, enjoy your time free of a keyboard! |
OK, I've updated the PR. It now uses shared helpers for How does this look, @stefanpenner? and happy new year folks! |
// Note that for the second item, reason.message will be "2", and for the | ||
// third item, reason.message will be "3". | ||
}, function(error) { | ||
// Code here never runs because allSettled never rejects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code will run if allSettled failed. e.g. was passed an incorrect type.
i believe with those last 2 comments, we should be good. |
how about now?
|
@decasia looks fantastic, thanks for the hard work! |
The existing
RSVP.all
method implements essentially a fail-fast method of resolving an array of promises. But sometimes you don't want the fail-fast behavior and instead want to be able to inspect the final states of a bunch of promises, whether they succeed or fail. One use case I've encountered is in doing validation handling when saving a bunch of related records in Ember — if you want to be able to trigger client-side logic based on the responses to all the record states,RSVP.all
is not really effective, because it doesn't continue after the first one.So this PR would add another method
RSVP.allSettled
that transforms an array of promises into a promise for an array of their states. These states will take one of the following formats:These result states are taken from a similar allSettled function in the Q library (compare also the allSettled tests). And for coherence with the existing RSVP codebase, I've kept the implementation, function and variable names, etc, as close as possible to
RSVP.all
for the time being.I've never sent a GitHub PR before, so I'd obviously be grateful for any tips or suggestions!