Return value

The tokio::select! macro returns the result of the evaluated <handler> expression.

  1. async fn computation1() -> String {
  2. // .. computation
  3. }
  4. async fn computation2() -> String {
  5. // .. computation
  6. }
  7. #[tokio::main]
  8. async fn main() {
  9. let out = tokio::select! {
  10. res1 = computation1() => res1,
  11. res2 = computation2() => res2,
  12. };
  13. println!("Got = {}", out);
  14. }

Because of this, it is required that the <handler> expression for each branch evaluates to the same type. If the output of a select! expression is not needed, it is good practice to have the expression evaluate to ().