diff --git a/async-message-passing/src/main.rs b/async-message-passing/src/main.rs index 8117d8e..957bed9 100644 --- a/async-message-passing/src/main.rs +++ b/async-message-passing/src/main.rs @@ -4,20 +4,26 @@ fn main() { trpl::run(async { let (tx, mut rx) = trpl::channel(); - let vals = vec![ - String::from("hi"), - String::from("from"), - String::from("the"), - String::from("future"), - ]; + 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; - } + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(500)).await; + } + }; - while let Some(value) = rx.recv().await { - println!("received '{value}'"); - } + let rx_fut = async { + while let Some(value) = rx.recv().await { + println!("received '{value}'"); + } + }; + + trpl::join(tx_fut, rx_fut).await; }); }