For AI agents: the complete documentation index is available at /tc39-atlas/en/llms.txt, the full documentation bundle is available at /tc39-atlas/en/llms-full.txt, and this page is available as Markdown at /tc39-atlas/en/proposals/year/pending/proposal-async-do-expressions.md.
  • English
  • async do expressions S1

    Proposal details
    Proposal overview

    The proposal introduces async do expressions to create an asynchronous context without requiring an immediately-invoked async function expression. It builds on the do expressions proposal and provides syntax that simplifies asynchronous operations inline. The proposal has preliminary spec text, indicating it is in an early stage of development.

    Note

    The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.

    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]));