On Thu, Jul 17, 2014 at 9:53 AM, C. Scott Ananian <[email protected]> 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; }); > })); > }; > ```
Nope, that'll accept with `undefined` if the first settled promise is rejected. ^_^ This is non-trivial to do correctly; you need to have rejected promises (except the last) resolve to an ever-pending promise instead. (I *think* that's correct.) ~TJ _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

