async-rs / async-std

Async version of the Rust standard library

Home Page:https://async.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: is awaiting `async_std::channel::recv` cancellation safe?

fprasx opened this issue · comments

I have some code that looks this:

#[async_std::main]
fn main() {
    tokio::select! {
        _ = channel.recv() => { ... }
        _ = other_future => { ... }
        _ = otherer_future => { ... }
    }
}

Is this safe? Thank you!

commented

The future returned by recv does not hold any future-local state, so it should be "cancellation-safe". That said I'd caution against using select!, and would recommend using combinators from futures-concurrency if possible.

To be honest, we (the Rust Async WG) should probably formalize the notion of "cancellation-safety" and bring it into the type system so this question can be answered from the function signature. But at the same time also work to replace select! as a primitive.