diff --git a/async-message-passing/src/main.rs b/async-message-passing/src/main.rs index dbe3883..98a3ade 100644 --- a/async-message-passing/src/main.rs +++ b/async-message-passing/src/main.rs @@ -4,7 +4,8 @@ fn main() { trpl::run(async { let (tx, mut rx) = trpl::channel(); - let tx_fut = async move { + let tx1 = tx.clone(); + let tx1_fut = async move { let vals = vec![ String::from("hi"), String::from("from"), @@ -13,17 +14,31 @@ fn main() { ]; for val in vals { - tx.send(val).unwrap(); + tx1.send(val).unwrap(); trpl::sleep(Duration::from_millis(500)).await; } }; let rx_fut = async { while let Some(value) = rx.recv().await { - eprintln!("received '{value}'"); + println!("received '{value}'"); } }; - trpl::join(tx_fut, rx_fut).await; + let tx_fut = async move { + let vals = vec![ + String::from("more"), + String::from("messages"), + String::from("for"), + String::from("you"), + ]; + + for val in vals { + tx.send(val).unwrap(); + trpl::sleep(Duration::from_millis(1500)).await; + } + }; + + trpl::join3(tx1_fut, tx_fut, rx_fut).await; }); }