Promise.any

Calvin Metcalf calvin.metcalf at gmail.com
Thu Jul 17 10:09:58 PDT 2014


It is implimented in bluebird
https://github.com/petkaantonov/bluebird/blob/master/API.md#any---promise


On Thu, Jul 17, 2014 at 12:53 PM, C. Scott Ananian <ecmascript at cscott.net>
wrote:

> I would think that proposed additions to the Promise spec ought to be
> prototyped in something like `prfun` or `bluebird` before being added
> to the spec.  There are lots of useful methods on Promise which I
> would add before `Promise.any`.
>
> Here's a very short implementation of `Promise.any`:
> ```
> 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; });
>   }));
> };
> ```
>
>   --scott
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
-Calvin W. Metcalf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140717/5d916413/attachment.html>


More information about the es-discuss mailing list