tokio::select!
select! polls multiple futures concurrently; completes when the first one finishes.
tokio::select! {
result = operation_one() => { handle_one(result) }
result = operation_two() => { handle_two(result) }
_ = shutdown_signal() => { break }
}
On completion of one branch, all other branches are dropped (their futures are cancelled).
tokio::select! {
_ = tokio::time::sleep(Duration::from_secs(30)) => {
eprintln!("connection timed out");
}
result = handle_connection(stream) => {
if let Err(e) = result { eprintln!("error: {}", e); }
}
}