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

Add is_closed and has_message to the Receiver #58

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

faern
Copy link
Owner

@faern faern commented Feb 2, 2025

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, and Disconnected. 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, calling has_message is going to provide better API ergonomics than matching an enum.

@szostid
Copy link

szostid commented Feb 3, 2025

Yes, this should cover all my use cases. Thanks!

@faern faern force-pushed the add-receiver-state-checking-methods branch from d2c4946 to 684b2fd Compare February 4, 2025 18:39
Allows polling the receiver for the channel state,
without changing it or without pulling any message out.
@faern faern force-pushed the add-receiver-state-checking-methods branch from 684b2fd to 5a73583 Compare February 4, 2025 18:44
@faern faern merged commit 5a73583 into main Feb 4, 2025
8 checks passed
@faern faern deleted the add-receiver-state-checking-methods branch February 4, 2025 18:44
@faern
Copy link
Owner Author

faern commented Feb 4, 2025

I just published version 0.1.10 with this functionality! Please let me know if it does not work as intended, or does not allow the desired use case.

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

Successfully merging this pull request may close these issues.

2 participants