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

Sending cancel safety #87

Open
BigBigos opened this issue Apr 11, 2024 · 1 comment
Open

Sending cancel safety #87

BigBigos opened this issue Apr 11, 2024 · 1 comment

Comments

@BigBigos
Copy link

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

@notgull
Copy link
Member

notgull commented Apr 11, 2024

Support would need to be added to the underlying concurrent-queue crate... which may be a lot harder in practice. I'd accept PRs but we would first need to come up with the underlying algorithm.

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

No branches or pull requests

2 participants