use std::time::Duration; use tokio::{join, select}; use tokio::sync::oneshot::channel; #[tokio::main] async fn main() { let (tx1, rx1) = channel::(); let a = tokio::spawn(async move { tokio::time::sleep(Duration::from_millis(2000)).await; let _ = tx1.send(1); println!(">>> send tx1"); }); select! { a = rx1 => { println!("tx: {:?}", a); } b = run() => { println!("run: {:?}", b); } c = tokio::time::sleep(Duration::from_millis(1500)) => { println!("timeout: {:?}", c); } } println!("join: {:?}", join!(a)); println!(">> pre end"); tokio::time::sleep(Duration::from_millis(2000)).await; println!(">> end"); } async fn run() { for i in 0.. { tokio::time::sleep(Duration::from_millis(300)).await; println!("# {}", i); } }