I like the following way of using `Promise.all()`:

```js
const all = Promise.all.bind(Promise);

const allTheThings = await all([pa, pb, pc]);
```

> On 3 Mar 2017, at 13:43, Andrea Giammarchi <andrea.giammar...@gmail.com> 
> wrote:
> 
> 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
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-- 
Dr. Axel Rauschmayer
a...@rauschma.de
dr-axel.de

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to