Excerpt from the Rust book: outside code blocks waiting for async code
โ Rust ๐ 2025-06-17 ๐ค surdeus ๐๏ธ 13Hello,
Sorry for making multiple posts on the topic I did not implement futures yet myself hence I have trouble understanding them well.
In an earlier post I asked whether a program can make progress while it is waiting for a future to be executed and I got a "depending on what happens inside trpl::run, yes" answer.
I just read this excerpt from the book: Applying Concurrency with Async - The Rust Programming Language
Note: Because all of this async code runs in an async block in a
trpl::runcall, everything within it can avoid blocking. However, the code outside it will block on therunfunction returning. Thatโs the whole point of thetrpl::runfunction: it lets you choose where to block on some set of async code, and thus where to transition between sync and async code. In most async runtimes,runis actually namedblock_onfor exactly this reason.
So this simply means: whenever I execute a future with a runtime like trpl, my code blocks until the future is complete. The code inside the async block passed to the runtime can make progress while waiting for the future to be available.
Correct?
3 posts - 2 participants
๐ท๏ธ rust_feed