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() {
|
fn main() {
|
||||||
trpl::run(async {
|
trpl::run(async {
|
||||||
let (tx, mut rx) = trpl::channel();
|
let (tx, mut rx) = trpl::channel();
|
||||||
|
|
||||||
let val = String::from("hi");
|
let vals = vec![
|
||||||
tx.send(val).unwrap();
|
String::from("hi"),
|
||||||
|
String::from("from"),
|
||||||
|
String::from("the"),
|
||||||
|
String::from("future"),
|
||||||
|
];
|
||||||
|
|
||||||
let received = rx.recv().await.unwrap();
|
for val in vals {
|
||||||
println!("Got: {received}");
|
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