diff --git a/async-message-passing/src/main.rs b/async-message-passing/src/main.rs index edb1ff5..8117d8e 100644 --- a/async-message-passing/src/main.rs +++ b/async-message-passing/src/main.rs @@ -1,11 +1,23 @@ +use std::time::Duration; + fn main() { trpl::run(async { let (tx, mut rx) = trpl::channel(); - let val = String::from("hi"); - tx.send(val).unwrap(); + let vals = vec![ + String::from("hi"), + String::from("from"), + String::from("the"), + String::from("future"), + ]; - let received = rx.recv().await.unwrap(); - println!("Got: {received}"); + 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}'"); + } }); }