How about awaiting Arrays ?

Andrea Giammarchi andrea.giammarchi at gmail.com
Fri Mar 3 12:43:54 UTC 2017


Not the first time I accidentally type the following:

```js
const allTheThings = await [pa, pb, pc];
```

I am assuming that JS will implicitly realize that'd be a `Promise.all([pa,
pb, pc])` call but nope.

Then I also realize it'd be cool to have other shortcuts too that play nice
with arrays such:

```js
Array.prototype.all = function all() { return Promise.all(this); };
Array.prototype.race = function race() { return Promise.race(this); };

// with the lovely addiction of ...
Array.prototype.any = function any() { return Promise.any(this); };

// with Promise.any being (sorry it was a tweet)
Promise.any = $ => new Promise((D,E,A,L) => {
  z = [];
  _ = $.map(($, i) => Promise.resolve($)
        .then(D, O => { z[i] = O; --_ || E(z) })
  ).length
});
```

So that ...
```js
const allTheThings = await [pa, pb, pc].all();
```

Yay? Nay? Silly? no-way?

I thought it was worth it to point this out.

Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170303/d5a26dcf/attachment.html>


More information about the es-discuss mailing list