fosskers's Blog

fosskers's Avatar Image
Haskell -> Rust -> Lisps
← All posts

Be careful about how you spawn threads in #rust

This

tokio::spawn(foo());

and this

tokio::spawn(async { foo().await });

Behave the same way.

However!

This does not compile:

tokio::spawn(foo().await);

and this silently does nothing.

tokio::spawn(async { foo() });

In the last example, foo is dropped entirely and never ran. So if you intend to run an async function (a Future) inside a manually specified async block, make sure to await it!

To like or reply, open original post on Emacs.ch