Skip to main content

Await Operator Top Level


Motivation

Proposal to add the await operator at the top level.

The await operator is currently only allowed inside async functions. This proposal allows await at the top level.

Using await at the top level avoid the uses of async/await in the following cases:

Using async/await:

await (async () => {
const response = await fetch('http://some-api.com')
return response.json()
})()

Instead of using async/await, we can use the following:

const response = await fetch('http://some-api.com')
const data = await response.json()

This proposal is needed to simplify the use of await at the top level.

Status

This proposal is currently at Stage 4.

Full documentation can be found here.