Add is_closed
and has_message
to the Receiver
#58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allows polling the receiver for the channel state, without changing it or without pulling any message out.
Does this allow using
oneshot
in the way you needed it @szostid ? Sure, if your code needs to know both whether or not the channel is disconnected and if there is a message, this solution requires two method calls (and two atomic loads) instead of one. But is that a real world use case? I imagine for the majority of places where you need to check the state you are either interested in knowing if there is a message to be read, or if the sender gave up and aborted.I could also consider going more towards your suggested route in #52. But only if we slim down the state enum to just expose
Empty
,Message
, andDisconnected
. The three states that any receiver code could reasonably care about? But that method would then not be mutually exclusive with these helper methods. For those that only need to check if a message is available or not, callinghas_message
is going to provide better API ergonomics than matching an enum.