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 {
|
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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue