Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is awaiting async_std::channel::recv cancellation safe? #1061

Closed
fprasx opened this issue Jun 16, 2023 · 1 comment
Closed

Question: is awaiting async_std::channel::recv cancellation safe? #1061

fprasx opened this issue Jun 16, 2023 · 1 comment

Comments

@fprasx
Copy link

fprasx commented Jun 16, 2023

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!

@yoshuawuyts
Copy link
Contributor

yoshuawuyts commented Jun 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants