Skip to content

is_closed for mpsc::{Receiver, UnboundedReceiver} #5032

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

Closed
wants to merge 1 commit into from

Conversation

farnz
Copy link
Contributor

@farnz farnz commented Sep 19, 2022

There's a use case for channels that wants to know up-front (before calling recv or try_recv)that there's a possibility of new messages coming in. Make it possible to check whether the channel is closed and empty, which implies that there will never be new messages on this channel.

Fixes: #4638

Motivation

Taken from #4638 - if you're building a pipe-type abstraction over an MPSC channel carrying byte buffers, then it's useful to know that the pipe is now terminated without having to handle the possibility of data arriving when you do the check.

Solution

Refactor so that I can see if the current block is closed without reading the value. I believe this avoids safety issues, since I never go near the actual data.

This is incomplete as-is, since it only allows you to look to see if the channel is closed, not check to see if there's data to be read, or to wait until data is available. I am working on those two items, to let you build a useful TcpStream equivalent from an MPSC channel.

There's a use case for channels that wants to know up-front (before
calling `recv` or `try_recv`)that there's a possibility of new messages
coming in. Make it possible to check whether the channel is closed and
empty, which implies that there will never be new messages on this
channel.

Fixes: tokio-rs#4638
@github-actions github-actions bot added the R-loom Run loom tests on this PR label Sep 19, 2022
@Noah-Kennedy
Copy link
Contributor

@faern #5016 is already in review.

@farnz
Copy link
Contributor Author

farnz commented Sep 19, 2022

@faern #5016 is already in review.

Thanks - for some reason, GitHub chose not to show me that pull request when I hit refresh this morning.

@farnz farnz closed this Sep 19, 2022
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync R-loom Run loom tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add method mpsc::Receiver::is_closed
3 participants