Angular.js: Implement $q.allSettled()

Created on 23 Aug 2014  路  12Comments  路  Source: angular/angular.js

Q.allSettled() is very useful when you need to know which promises were resolved and which were rejected.

5497 Was closed with "Won't fix", but the promise refactor mentioned as the alternative in the comments never happened.

Most helpful comment

Implemented it and uploaded it to the bower registry:

https://github.com/ohjames/angular-promise-extras

All 12 comments

At the 1.3.x branch, $q is prototype based, so this can be added thru an extension. Still believe this does not belong to the core, but something that an external module can add to $q

You have to be a bit careful with it because there are technically 2 different promise implementations in angular now --- they are both essentially the same, but use different strategies for scheduling the next tick. In the version that landed (unfortunately!) they don't share a parent prototype with each other, so you'd need to add these extra things to both versions of the promise. I know it's really stupid, but what can you do =(

@caitp Only one is exposed as $q, and the implementation of this feature is a static method, so it would only need to be implemented in the user-facing version.

@lgalfaso I argue that it is more useful than all therefore should be part of the core. https://github.com/angular/angular.js/pull/8738#issuecomment-53338042

I agree with @deckar01: allSettled is much more useful than all and I'd really like to see it in the core. all has rarely been useful for me because of its limitations.

Where I would probably differ with @deckar01 is how allSettled should be implemented within Angular. I would propose sticking with q's allSettled API instead of what was proposed in @deckar01's PR (the difference being what is returned once the promises are settled).

@deckar01 agreed

It will be good to implement allSettled in $q.
I thought it will be there where I started to make my validation system, and it was a disappointment to find out that it's missing.

It should be straightforward to create an external module that adds this
funtionality to $q

There is something alike, but there is no bower or node support.
https://gist.github.com/Aaronius/46ae4a0f8ff052cd24f0

Implemented it and uploaded it to the bower registry:

https://github.com/ohjames/angular-promise-extras

:+1:

Just for fun, here my implementation https://github.com/niqdev/angular-q-extras

Was this page helpful?
0 / 5 - 0 ratings