[whatwg] Promise.every() arguments

Alec Flett alecflett at chromium.org
Tue Aug 20 14:42:37 PDT 2013


Hey spreading sounds great... I miss that from python.

But, the promise array issue still feels really awkward to me.

One confusing example of this is that if you *do* pass an array,
(incorrectly) the then() gets an array of an array of unresolved promises:

Promise.every([Promise.resolve(1),
Promise.resolve(2)]).then(function(results) {
    // here results is [[Promise, Promise]]
})

Which again from a developer perspective seems more like Promise.every()
forgot to resolve all the promises, not that you're using the API wrong.

Whereas if the API were the other way around, and you pass
Promise.every(Promise.resolve(1), Promise.resolve(2)) by accident,
Promise.every() can throw an exception to say "don't do that, you clearly
misunderstand"

Promises are going to be out way before ES6, it seems unfortunate that
everyone's going to have to use Promise.every.apply though, since spreading
is a syntax error in non-ES6... it means you can't polyfill it in the
general case. (And maybe there's some generic answer to that aspect of ES6
- I'm admittedly not up to speed on the ES6 future-compatible story)

Alec


On Tue, Aug 20, 2013 at 2:23 PM, Anne van Kesteren <annevk at annevk.nl> wrote:

> On Tue, Aug 20, 2013 at 10:00 PM, Tab Atkins Jr. <jackalmage at gmail.com>
> wrote:
> > ES6 has array spreading, so you can do `Promise.every(...pending)`.
> > This already works in Firefox, and V8 (Chrome's JS engine) is adding
> > these kinds of features as well.
>
> Domenic made an argument somewhere that since the value of the promise
> will be an array, the input should maybe be an array too. Seemed
> somewhat reasonable. I agree that due to spreading we shouldn't
> consider OP's argument though.
>
>
> --
> http://annevankesteren.nl/
>



More information about the whatwg mailing list