Proper patterns for equivalent of when.all()

11 views
Skip to first unread message

thanpolas

unread,
Mar 25, 2013, 12:45:24 PM3/25/13
to cuj...@googlegroups.com
I am trying to figure out how to know the full outcome of handling multiple promises.

As per the documentation of when.all():

If any of the promises is rejected, the returned promise will be rejected with the rejection reason of the first promise that was rejected.

One thing that also happens is that the returned promise, gets rejected the moment the first promise gets rejected. Which means that the when.all() method will not wait for all promises to finish if one of them rejects.

That can be convenient for some cases... 

I want to know when all promises have finished, and what was their outcome individually regardless if they rejected or resolved...

What pattern would you suggest for this?

Brian Cavalier

unread,
Mar 25, 2013, 1:41:04 PM3/25/13
to cuj...@googlegroups.com
Great question.  Yep, the behavior of when.all() is exactly what you described: it wants all the promises to be fulfilled, and the instant any one of them rejects, the overall when.all operation rejects, since it has become impossible to fulfill all the promises.

I def agree that a way to wait for all promises to settle (fulfill or reject) is useful!  Have a look at this issue and let us know your thoughts :)  In the meantime, if you need this functionality, check out this gist from a proof-of-concept implementation I did a while back.
Reply all
Reply to author
Forward
0 new messages