Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Excerpt from the Rust book: outside code blocks waiting for async code
Excerpt from the Rust book: outside code blocks waiting for async code
โ rust ๐ 2025-06-17 ๐ค surdeus ๐๏ธ 2Hello,
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 therun
function returning. Thatโs the whole point of thetrpl::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 namedblock_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
๐ท๏ธ rust_feed