Skip to content

Sending cancel safety #87

Open
Open
@BigBigos

Description

@BigBigos

I believe Sender::send() is not cancel safe in regard that it takes ownership of the value to be sent. If the future is cancelled, the value is gone with no way to recover it. This makes using it inconvenient within the select! loop.

tokio's mpsc::Sender suggests using reserve() and Permit::send() to resolve this problem. reserve() returns a future, but it does not consume any value by itself. Permit::send() then can be used to send the value without any blocking.

Can a similar API be implemented for async-channel? Is that feasible?

[1] https://docs.rs/tokio/latest/tokio/macro.select.html
[2] https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.Sender.html#cancel-safety

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions