Is tokio's `select!` cancel safe?

⚓ Rust    📅 2026-02-04    👤 surdeus    👁️ 6      

surdeus

When using a future with select! in a loop and to avoid loosing data the futures must be "cancel safe".

My question is: is the following future cancel safe?

async fn foo() {
    select! {
        _ = goo() => { /* ... */ }
        _ = hoo() => { /* ... */ }
    }
}

So if I have a loop with a select! that use foo

loop {
    select! {
        _ = sleep(Duration::from_secs(1)) => { /* ... */ }
        _ = foo() => { /* ... */ }
    }
}

Does any data loss may happen?

The docs for select! is quite large, so maybe a miss the information but is seems there is no information about nested select! or its the cancel safety-ness.

1 post - 1 participant

Read full topic

🏷️ Rust_feed