await.ops proposal
The rendered spec text. Playground Link
Introduce await.all / await.race / await.allSettled / await.any to simplify the usage of Promises
Stage: 1
Champions: Jack Works, Jordan Harband
Motivation
- To simplify the usage of a set of Promises. (Previous discussions: https://es.discourse.group/t/allow-awaiting-on-arrays/178/19)
- To simplify the usage of concurrent for loop in async functions.
Usage:
// before
await Promise.all(users.map(async x => fetchProfile(x.id)))
// after
await.all users.map(async x => fetchProfile(x.id))
Syntax:
await.all expr
// eq: await Promise.all(expr)
await.race expr
// eq: await Promise.race(expr)
await.allSettled expr
// eq: await Promise.allSettled(expr)
await.any expr
// eq: await Promise.any(expr)