-
Is there something like I want to get the first If all failed, then return async fn connect(&self, _: &Arc<Client>) -> std::io::Result<TcpStream> {
tokio::select! {
conn1 = TcpStream::connect(SocketAddr::new(Ipv4Addr::new(1,2,3,4).into(), 80)) => {
return conn1 // TODO if error, not return
}
conn2 = TcpStream::connect(SocketAddr::new(Ipv4Addr::new(5,6,7,8).into(), 80)) => {
return conn2 // TODO if error, not return
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
Darksonn
May 20, 2022
Replies: 1 comment 2 replies
-
Use a pattern to disable the async fn connect(&self, _: &Arc<Client>) -> std::io::Result<TcpStream> {
tokio::select! {
Ok(conn1) = connect1() => Ok(conn1),
Ok(conn2) = connect2() => Ok(conn2),
else => Err(...)
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
lz1998
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use a pattern to disable the
tokio::select!
branch if it returns an error.