Welcome! Please see the About page for a little more info on how this works.

+4 votes
in ClojureScript by

There is a lot of discussion around the web related to adding ES2018 async/await to ClojureScript, be it feature requests[1][2], proposals[3], or experimentation[4][5].

I am posting this question so there is a central place where people can upvote and bring attention to the Clojure core team, and possibly help prioritize consideration of this feature.

I am aware it is not as easy as adding keywords to emitted JS code. I am aware of workarounds like using macros from promesa, core.async, or kitchen-async. I am also aware that there must be a strong use case for consideration on adding this feature. Everything I've mentioned, and more, has been discussed at one point in the links below.

[1] https://groups.google.com/g/clojurescript/c/scUMhU-ctEM
[2] https://www.reddit.com/r/Clojure/comments/f4nlau/clojurescript_and_asyncawait/
[3] https://observablehq.com/@shaunlebron/proposal-generators-and-async-functions-in-clojurescript#blockers
[4] https://twitter.com/roman01la/status/1155602189311717377
[5] https://twitter.com/borkdude/status/1639579880336621570

Note that both squint and cherry support async await: https://github.com/squint-cljs/cherry

I should support the name `js-await` though, as this makes more sense, given that there is js-delete, etc.

If the CLJS core team decides that they want to have async/await, I'm volunteering to implement it (since I already had to figure this out in cherry/squint, I don't think it will take me that long).

Promesa is quite good though in the meanwhile.

1 Answer

+3 votes

Note that shadow-cljs has had support for js-await for a while now.

See the announcement post here:

This isn't quite async/await, but if you ask me if doesn't have to be.
It is implemented as a quite trivial macro. It has the same syntactical semantics and there is absolutely no need to "tag" any function as async. It just becomes so by nature of returning a promise.

I don't think changing the compiler to emit actual async/await is worth the effort. The macro gives you 90% of the solution for 1% of the effort. Same goes for libs such as promesa. This is easily solved in user space.