What's the point of async <block-or-exp>?

I’m referring to this.

Is it equivalent to just taking that block of code and putting it in an async private function? Or is there an additional benefit to declaring an async block inline? I couldn’t find any examples.

From a language design perspective, one point is that it decomposes the monolithic ad-hoc notion of “async function” present in some recent languages into two separate, simpler concepts. That makes sense, because async computation doesn’t really have much to do with functional abstraction per se. Conceptually, there are no async functions in Motoko, only functions whose body happens to be an async expression.

In terms of practical programming, it is correct that an async expression can usually be outlined into an auxiliary function. But that is naturally true for any feature in a language with sufficiently powerful functions. The ability to use a feature inside a function e.g. has the benefit that it can directly access (some) of its local bindings.

2 Likes