What is Nostr?
Colin /
npub126f…juh4
2024-02-05 06:30:06

Colin on Nostr: Be careful about how you spawn threads in #rust This tokio::spawn(foo()); and this ...

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!
Author Public Key
npub126fvxt60z0ztelstasxykk4epyr9tv8evmjwkcnxpukatx8trstsuhjuh4