expression

Keep a losing future across select calls

Pin a future outside a selection and borrow it as a branch. If another branch wins, the owned future remains available; this avoids restarting its progress. Do not poll a completed future again unless its contract permits that. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): other branch timer complete Common mistake: Creating a new timer each time a selection loop runs, thereby moving the deadline.

Formal Syntax & Structure

rust syntaxrust
tokio::pin!(future); &mut future

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() {    use tokio::time::{sleep, Duration};    let wait = sleep(Duration::from_secs(5));    tokio::pin!(wait);    tokio::select! {        biased;        _ = async {} => println!("other branch"),        _ = &mut wait => unreachable!(),    }    wait.await;    println!("timer complete");}
Rust Reference