Skip to content
master
Switch branches/tags
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Jan 15, 2021
Jan 20, 2021
Jan 20, 2021

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

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

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

async `do` expressions for JavaScript

Resources

Releases

No releases published

Packages

No packages published

Languages