For AI agents: the complete documentation index is available at /tc39-atlas/llms.txt, the full documentation bundle is available at /tc39-atlas/llms-full.txt, and this page is available as Markdown at /tc39-atlas/proposals/stage/1/proposal-await.ops.md.
  • 简体中文
  • await operations S1

    中文标题:await 操作

    提案概览
    提案速览

    该提案引入了 await.all、await.race、await.allSettled 和 await.any,以异步/等待风格提供并发 Promise 工具,减少了对常见模式直接使用 Promise 方法的需求。

    Note

    以下 README 来自上游仓库,其中的阶段或状态标注可能滞后;当前信息以提案概览为准。

    await 操作提案

    渲染的规范文本游乐场链接

    引入 await.all / await.race / await.allSettled / await.any 以简化异步函数的使用

    阶段:1

    champions: Jack Works, Jordan Harband

    动机

    当开发者使用异步函数时,如果他们想并发处理多个任务(例如 Promise.all),他们必须了解 Promise,这是某种意义上的“抽象泄漏”。

    本提案旨在通过引入异步等待风格的并发 Promise 工具来解决这个问题。

    草案解决方案

    // 之前
    await Promise.all(users.map(async x => fetchProfile(x.id)))
    
    // 之后
    await.all users.map(async x => fetchProfile(x.id))

    语法:

    await.all expr
    // 等价于:await Promise.all(expr)
    
    await.race expr
    // 等价于:await Promise.race(expr)
    
    await.allSettled expr
    // 等价于:await Promise.allSettled(expr)
    
    await.any expr
    // 等价于:await Promise.any(expr)