Run sending and receiving parts separately
This commit is contained in:
parent
50dfffdb70
commit
82780c0009
1 changed files with 19 additions and 13 deletions
|
@ -4,20 +4,26 @@ fn main() {
|
|||
trpl::run(async {
|
||||
let (tx, mut rx) = trpl::channel();
|
||||
|
||||
let vals = vec![
|
||||
String::from("hi"),
|
||||
String::from("from"),
|
||||
String::from("the"),
|
||||
String::from("future"),
|
||||
];
|
||||
let tx_fut = async {
|
||||
let vals = vec![
|
||||
String::from("hi"),
|
||||
String::from("from"),
|
||||
String::from("the"),
|
||||
String::from("future"),
|
||||
];
|
||||
|
||||
for val in vals {
|
||||
tx.send(val).unwrap();
|
||||
trpl::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
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}'");
|
||||
}
|
||||
let rx_fut = async {
|
||||
while let Some(value) = rx.recv().await {
|
||||
println!("received '{value}'");
|
||||
}
|
||||
};
|
||||
|
||||
trpl::join(tx_fut, rx_fut).await;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue