Introduce pauses between sending messages
This commit is contained in:
parent
7ecb5e30c5
commit
50dfffdb70
1 changed files with 16 additions and 4 deletions
|
@ -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}'");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue