W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2013

Re: [whatwg] Promise.every() arguments

From: Alec Flett <alecflett@chromium.org>
Date: Tue, 20 Aug 2013 14:42:37 -0700
Message-ID: <CAHWpXeaw+Q1JYwKTW6Cvw9wwU903SASPmS=kGbbk9RO8X1R0QA@mail.gmail.com>
To: Anne van Kesteren <annevk@annevk.nl>
Cc: WHATWG <whatwg@lists.whatwg.org>, "Tab Atkins Jr." <jackalmage@gmail.com>, Alec Flett <alecflett@chromium.org>
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.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

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)


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

> On Tue, Aug 20, 2013 at 10:00 PM, Tab Atkins Jr. <jackalmage@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/
Received on Tuesday, 20 August 2013 21:43:21 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:23 UTC