Re: Promise.any

2014-07-17 Thread C. Scott Ananian
f the rejection handling of the `bluebird` utility functions `Promise.some()` and `Promise.any()`. I considered them for `prfun` and decided that I didn't want to support this API. Note also that the matter of merging/reporting all the rejections is awkward; `bluebird` uses a new `AggregateE

Re: Promise.any

2014-07-17 Thread Mark S. Miller
kup and > racing it against the network, you want to display the data from whichever > source resolves first, and only display a fallback resource when neither > the cache nor the network are available. > > In the same thread, [Tab Atkins mentioned][2] `Promise.any` fulfills this > u

Re: Promise.any

2014-07-17 Thread C. Scott Ananian
On Thu, Jul 17, 2014 at 1:41 PM, Tab Atkins Jr. 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 = []; retur

Re: Promise.any

2014-07-17 Thread Tab Atkins Jr.
d 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.len

Re: Promise.any

2014-07-17 Thread Tab Atkins Jr.
kup and racing > it against the network, you want to display the data from whichever source > resolves first, and only display a fallback resource when neither the cache > nor the network are available. > > In the same thread, [Tab Atkins mentioned][2] `Promise.any` fulfills this > u

Re: Promise.any

2014-07-17 Thread Calvin Metcalf
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(promi

Re: Promise.any

2014-07-17 Thread C. Scott Ananian
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 `Promis

Promise.any

2014-07-17 Thread Tobie Langel
ither the cache nor the network are available. In the same thread, [Tab Atkins mentioned][2] `Promise.any` fulfills this use case and was briefly discussed within TC39 before being abandoned. I'd imagine a pseudo implementation would look something like the below, though you might want to s