What is the difference between `|_| async move {}` and `async move |_| {}`

One is the async block (a closure with async block as its body to be precise), while the other is async closure. Per async/await RFC:

async || closures

In addition to functions, async can also be applied to closures. Like an async function, an async closure has a return type of impl Future<Output = T>, rather than T.

On the other hand:

async blocks

You can create a future directly as an expression using an async block. This form is almost equivalent to an immediately-invoked async closure:

 async { /* body */ }

 // is equivalent to

 (async || { /* body */ })()

except that control-flow constructs like return, break and continue are not allowed within body.

The move keyword here is to denote that the async closure and block are to capture ownership of the variables they close over.

And apparently, async closure is still deemed to be unstable. It has this tracking issue.

Leave a Comment