tc39/proposal-await.ops

Introduce await.all / await.race / await.allSettled / await.any to simplify the usage of Promises

HTML

309

40 commits

updated Nov 20, 2022

See the code

README

await operations proposal

The rendered spec text. Playground Link

Introduce await.all / await.race / await.allSettled / await.any to simplify the usage of async functions

Stage: 1

Champions: Jack Works, Jordan Harband

Motivation

When developers use async functions, they have to know about Promise if they want to handle multiple tasks concurrently (Promise.all, eg), this is some kind of "abstraction leak".

This proposal is intended to fix the problem by introducing concurrent Promise utils in the async-await style.

Drafted solution

// 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)

Contributors

Jack-Works

34 commits

JLHwung

2 commits

ljharb

2 commits

ExE-Boss

1 commits

tc39/proposal-await.ops

Introduce await.all / await.race / await.allSettled / await.any to simplify the usage of Promises

HTML

309

40 commits

updated Nov 20, 2022

See the code

README

await operations proposal

The rendered spec text. Playground Link

Introduce await.all / await.race / await.allSettled / await.any to simplify the usage of async functions

Stage: 1

Champions: Jack Works, Jordan Harband

Motivation

When developers use async functions, they have to know about Promise if they want to handle multiple tasks concurrently (Promise.all, eg), this is some kind of "abstraction leak".

This proposal is intended to fix the problem by introducing concurrent Promise utils in the async-await style.

Drafted solution

// 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)

Contributors

Jack-Works

34 commits

JLHwung

2 commits

ljharb

2 commits

ExE-Boss

1 commits

Languages

HTML

100.0%