#[tokio::main]
async fn main() -> io::Result<()> {
// ...
let handle1 = tokio::spawn( async move {method1().await });
let handle2 = tokio::spawn( async move {method2().await });
let handle3 = tokio::spawn( async move {method3().await });
let (handle1_ret, handle2_ret, handle3_ret) = tokio::join!(handle1, handle2, handle3)?;
match handle1_ret {
Ok(_) => info!("handle1 closed");
Err(e) => error!("handle1 failed");
}
match handle2_ret {
Ok(_) => info!("handle2 closed");
Err(e) => error!("handle2 failed");
}
match handle3_ret {
Ok(_) => info!("handle3 closed");
Err(e) => error!("handle3 failed");
}
Ok(())
}
tokio::join! got stuck there even there is an error from method1/method2/method3.
What I want is if method1 or method2 or mehtod3 got any error, tokio::join! should return and then the program should close (other running methods will terminate).