Run sending and receiving parts separately

This commit is contained in:
Manuel Thalmann 2025-04-06 21:30:07 +02:00
parent 50dfffdb70
commit 82780c0009
Signed by: manuth
SSH key fingerprint: SHA256:HsMLC+7kJWALP6YCYCoopxNbUnghwSGLVcG76SECT5c

View file

@ -4,20 +4,26 @@ fn main() {
trpl::run(async { trpl::run(async {
let (tx, mut rx) = trpl::channel(); let (tx, mut rx) = trpl::channel();
let vals = vec![ let tx_fut = async {
String::from("hi"), let vals = vec![
String::from("from"), String::from("hi"),
String::from("the"), String::from("from"),
String::from("future"), String::from("the"),
]; String::from("future"),
];
for val in vals { for val in vals {
tx.send(val).unwrap(); tx.send(val).unwrap();
trpl::sleep(Duration::from_millis(500)).await; trpl::sleep(Duration::from_millis(500)).await;
} }
};
while let Some(value) = rx.recv().await { let rx_fut = async {
println!("received '{value}'"); while let Some(value) = rx.recv().await {
} println!("received '{value}'");
}
};
trpl::join(tx_fut, rx_fut).await;
}); });
} }