-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add isfull for buffered Channels #52470
base: master
Are you sure you want to change the base?
Conversation
Do we have a supported way to check if a channel is buffered? Currently, Another issue is - suppose a user calls |
Not sure about the first comment. I'd say we should export I guess the difference in my view comes from the fact that the main purpose to me for Anyways, I am also happy with I am open for suggestions. |
For buffered channels, the equivalent measure would be how many takers are currently blocked waiting for input. The channel is full if there are more putters waiting than takers waiting (it is also how a buffered channel can exceed the queue length, since it is nbuffered+nwaiters) Wouldn't tryput be more useful here than isfull? We could have both, but it feels already a little awkward to me that a lot of this API assumes single reader-writer (like this PR) and that could mislead users to use race-y API instead of other equivalent APIs |
FWIW, #41966 is stuck because the original author is gone and it needed someone to come take over and make decisions there |
OK I feel it's vibing towards |
I'd say make a new one, but it is fine if you want to change this one instead to include it |
Currently the only way to check if a
Channel
is full by accessing its fields.data
and.sz_max
which is neither a good practice, nor documented.Checking if a (buffered) channel is full is mandatory when somebody wants to discard the data to avoid e.g. memory pile-up or redirect it to another channel (load-balancing).
This PR implements
isfull(c::Channel)
which returnstrue
if the number of available items is equal (or exceeds -- still not sure if that case can happen due to race conditions) the size of the buffered channel.A somewhat similar problem is also addressed in #41966 with the implementation of
tryput!
.