Skip to content

tc39/proposal-async-do-expressions

Folders and files

Image for: Folders and files
NameName
Last commit message
Last commit date

Latest commit

Image for: Latest commit
 

History

Image for: History
5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image for: Repository files navigation

ECMAScript proposal: async do expressions

async do expressions allow you to introduce an asynchronous context within synchronous code without needing an immediately-invoked async function expression.

This proposal builds off of the do expressions proposal.

This proposal has preliminary spec text.

Motivation

Image for: Motivation

Currently the boundary between synchronous and asynchronous code requires defining and invoking an async function. In the case that you just want to perform a single operation, that's a lot of syntax for a relatively primitive operation: (async () => {...})(). This lets you write async do {...} instead.

Examples

Image for: Examples
// at the top level of a script

async do {
  await readFile('in.txt');
  let query = await ask('???');
  // etc
}
Promise.all([
  async do {
    let result = await fetch('thing A');
    await result.json();
  },
  async do {
    let result = await fetch('thing B');
    await result.json();
  },
]).then(([a, b]) => console.log([a, b]));

About

Image for: About

async `do` expressions for JavaScript

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

Image for: Releases
No releases published

Packages

Image for: Packages 0
No packages published

Contributors 2

Image for: Contributors 2
  •  
  •  

Languages

Image for: Languages