Promise.any

C. Scott Ananian ecmascript at cscott.net
Thu Jul 17 11:31:00 PDT 2014


On Thu, Jul 17, 2014 at 1:41 PM, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
>
> Nope, that'll accept with `undefined` if the first settled promise is
> rejected.  ^_^  This is non-trivial to do correctly; you need to have

Fixed:
```
Promise.any = function(promises) {
   var errors = [];
   return Promise.race(promises.map(function(p) {
      return p.catch(function(e) { errors.push(e); if (errors.length >=
 promises.length) throw errors; return Promise.race(); });
   }));
};
```
 --scott


More information about the es-discuss mailing list