DEV Community

Discussion on: ECMAScript 2021 (ES12) new features

Collapse
 
jackydev profile image
JacKyDev

Heyho,

Good content. I just miss the case, Promise.any with a reject and a resolve so that is clearer.

Collapse
 
naimlatifi5 profile image
Naim Latifi

Hi JackyDev,

Thank you! Sure and I will try to explain here. With the reject if none of the promise is resolved then an Aggregate error is returned as in the example that I intentionally rejected C and D to see the error. In the case of resolve, if any of the promise is resolved in the example A resolves faster than B the result is returned and doesn't care about B. Promise.any() works in opposite way with Promise.all() where all promises need to be resolved for a single promise to resolve. Hope this made more clear when working with promise.any :)