Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
- Combining asynchronous code with synchronous code that can cause blocking is never a wise choice.
When calling asynchronous code from a synchronous context,
use
futures::executor::block_on
and spawn the async code to a dedicated runtime, because the former will block the current thread. On the other hand, if you have to call blocking synchronous code from an asynchronous context, it is recommended to usetokio::task::spawn_blocking
to execute the code on a dedicated executor that handles blocking operations.
Tutorials
Basics of Rust Concurrency (Atomics and Locks Chapter 1)