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

Tab Atkins Jr. jackalmage at gmail.com
Fri Jun 14 08:06:00 PDT 2013


On Fri, Jun 14, 2013 at 5:00 PM, Tetsuharu OHZEKI
<saneyuki.snyk at 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



More information about the whatwg mailing list