ClojureScript Gets Async/Await

ClojureScript Gets Async/Await

ClojureScript 支持 Async/Await

ClojureScript 1.12.145 Release 07 May 2026 ClojureScript Team We’re happy to announce a new release of ClojureScript. If you’re an existing user of ClojureScript please read over the following release notes carefully. ClojureScript 1.12.145 版本发布于 2026 年 5 月 7 日。ClojureScript 团队很高兴地宣布 ClojureScript 的新版本发布。如果您已经是 ClojureScript 的用户,请仔细阅读以下发行说明。

Async Functions

异步函数 (Async Functions)

Now that ClojureScript targets ECMAScript 2016 we can carefully choose new areas of enhanced interop. Starting with this release, hinting a function as ^:async will make the ClojureScript compiler emit an JavaScript async function: 由于 ClojureScript 现在以 ECMAScript 2016 为目标,我们可以谨慎地选择新的领域来增强互操作性。从本次发布开始,将函数标记为 ^:async 将使 ClojureScript 编译器生成 JavaScript 的 async 函数:

(refer-global :only '[Promise])
(defn ^:async foo [n]
  (let [x (await (Promise/resolve 10))
        y (let [y (await (Promise/resolve 20))]
            (inc y))
        ;; not async
        f (fn [] 20)]
    (+ n x y (f))))

This also works for tests: 这也适用于测试:

(deftest ^:async defn-test
  (try
    (let [v (await (foo 10))]
      (is (= 61 v)))
    (let [v (await (apply foo [10]))]
      (is (= 61 v)))
    (catch :default _ (is false))))

In the last Clojure survey support for async functions dominated the list of desired ClojureScript enhancements for JavaScript interop. This enhancement eliminates the need to take on additional dependencies for the common cases of interacting with modern Browser APIs and popular libraries. 在最近的一次 Clojure 调查中,对 async 函数的支持在 ClojureScript JavaScript 互操作性增强需求列表中名列前茅。这一改进消除了在与现代浏览器 API 和流行库交互的常见场景中引入额外依赖的需求。

For a complete list of fixes, changes, and enhancements to ClojureScript see here. 有关 ClojureScript 修复、更改和增强功能的完整列表,请参阅此处

Contributors

贡献者

Thanks to all of the community members who contributed to ClojureScript 1.12.145: Michiel Borkent. 感谢所有为 ClojureScript 1.12.145 做出贡献的社区成员:Michiel Borkent。