How to use tokio select macro

The tokio::select! macro runs multiple futures concurrently and executes the code block for whichever one finishes first.

Use the tokio::select! macro to run multiple futures concurrently and execute the block corresponding to the one that completes first.

use tokio::time::{sleep, Duration};

#[tokio::main]
async fn main() {
    tokio::select! {
        _ = sleep(Duration::from_secs(1)) => println!("One second passed"),
        _ = sleep(Duration::from_secs(2)) => println!("Two seconds passed"),
    }
}