Proposal: `await [p1, p2]` (equivalent to `await Promise.all([p1, p2])`)

Olivier Lalonde olalonde at gmail.com
Wed Oct 26 07:11:36 UTC 2016


I have no idea if this has been discussed already but I thought it'd be
nice to have the following syntax sugar for async/await.

The idea would be that any array that follows `await` would be wrapped into
a Promise.all() call. For example, `await [p1,p2]` would be the equivalent
of `await Promise.all([p1,p2])`.

It would make some more complex expressions easier to read:

```
  const downloads = await Promise.all(regs.map(reg => client.get(reg.url, {
    responseType: 'arraybuffer',
  })))
```

vs

```
  const downloads = await regs.map(reg => client.get(reg.url, {
    responseType: 'arraybuffer',
  }))
```

In many async/await code bases, it might remove the last use case for
typing `Promise` directly.

-- 
- Oli

Oli Lalonde
http://www.syskall.com <-- connect with me!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161026/f2040f67/attachment.html>


More information about the es-discuss mailing list