Ben Chuanlong Du's Blog

It is never too late to learn.

Async in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

  1. Minimizing usage of async Rust. Refactor coded as much as possible to be in sync functions, and have async just be little "router wrappers" for waiting on stuff and feeding it to sync functions. See good discussion at Avoid Async Rust at all costs” - comments from experts? .

  2. 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 use tokio::task::spawn_blocking to execute the code on a dedicated executor that handles blocking operations.

Issues in Async Rust

Tutorials

Basics of Rust Concurrency (Atomics and Locks Chapter 1)

References

Comments