Excerpt from the Rust book: outside code blocks waiting for async code

โš“ rust    ๐Ÿ“… 2025-06-17    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

Hello,

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::run call, everything within it can avoid blocking. However, the code outside it will block on the run function returning. Thatโ€™s the whole point of the trpl::run function: 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, run is actually named block_on for 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

Read full topic

๐Ÿท๏ธ rust_feed