If I have an async block and it is interrupted, does program execution continue after the block?

⚓ rust    📅 2025-06-07    👤 surdeus    👁️ 3      

surdeus

Hello,

I am following the Rust book and think nowhere have I seen an answer to this question:
they give an improvement to the problem that if the below code is wrapped into only one outer async loop then the second while let loop is executed only after the first loop ends.
To me the fact that this wrapping in 2 async blocks solves this problem implies that program execution continues after the async block which is stopped and resumed at a later time.
Am I right? I gave a short code example of how I assume the execution flow to work.

let tx_fut = async {
            let vals = vec![
                String::from("hi"),
                String::from("from"),
                String::from("the"),
                String::from("future"),
            ];

            for val in vals {
                tx.send(val).unwrap();
                trpl::sleep(Duration::from_millis(500)).await;
            }
        };

        let rx_fut = async {
            while let Some(value) = rx.recv().await {
                println!("received '{value}'");
            }
        };

        trpl::join(tx_fut, rx_fut).await;
async {
// ...
// execution stops here
foo().await;
// ...
}

// and immediately continues here
let x = 5;
continue(x);
//...

5 posts - 3 participants

Read full topic

🏷️ rust_feed