-
Hey, I'm new in rust and tokio~ Lines 60 to 79 in e42317b I would like to cancel both sides if any task return, but I do not how to move let (mut ri, mut wi) = inbound.split();
let (mut ro, mut wo) = outbound.split();
let client_to_server = async {
io::copy(&mut ri, &mut wo).await?;
wo.shutdown().await;
wi.shutdown().await;
};
let server_to_client = async {
io::copy(&mut ro, &mut wi).await?;
wi.shutdown().await;
wo.shutdown().await;
};
tokio::try_join!(client_to_server, server_to_client)?; |
Beta Was this translation helpful? Give feedback.
Answered by
Darksonn
Jan 8, 2021
Replies: 1 comment 4 replies
-
How about this? let (mut ri, mut wi) = inbound.split();
let (mut ro, mut wo) = outbound.split();
// This runs both until _one_ of them returns.
tokio::select! {
res = io::copy(&mut ri, &mut wo) => res?,
res = io::copy(&mut ro, &mut wi) => res?,
}
wi.shutdown().await?;
wo.shutdown().await?; |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
windniw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about this?