Re: [whatwg] How works Promise.any() if it was called with resolved promises?

On Fri, Jun 14, 2013 at 5:00 PM, Tetsuharu OHZEKI
<saneyuki.snyk@gmail.com> wrote:
> Thank you.
>
> By the way, if we call `Promise.any()` with some resolved and rejected
> promises  and add new fulfillCallback to it, will the fulfillCallback
> be invoked once with parameters which are values of all promises
> passed to `Promises.any()`?  Or will the fulfillCallback be invoked
> with values which are resolved promises only?
>
> like this case:
> ```
> // p1, p2 are resolved promises. p3 is pending, rejected, or resolved one.
> Promise.any(p1, p2, p3).then(function fulfillCallback(){
>   // What will this function be passed?
> });

If you check out the spec, Promise.any() runs down its list of
arguments in order, giving them the ability to resolve the returned
promise.  So if several of them are already resolved, the first one in
argument order is what gets used - the rest of them *try* to fulfill
the promise, but it's already been resolved, so it doesn't do
anything.

~TJ

Received on Friday, 14 June 2013 15:06:44 UTC