From 50dfffdb702caafabb8aa96169e21225a4871286 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann <m@nuth.ch> Date: Sun, 6 Apr 2025 21:13:59 +0200 Subject: [PATCH] Introduce pauses between sending messages --- async-message-passing/src/main.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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}'"); + } }); }