Skip to content

Conversation

@yug49
Copy link
Contributor

@yug49 yug49 commented Dec 4, 2025

Resolves #222

Description

This PR addresses the issue of ambiguous channel closure handling by introducing a ChannelState enum with explicit Open and Closed variants that makes the code intent clear:

pub enum ChannelState {
    /// The channel is open and the message was successfully sent.
    Open,
    /// The channel is closed (receiver dropped), no further messages can be sent.
    Closed,
}

Before vs After

Before:

if !sender.try_stream(Notification::ReorgDetected).await {
    return; // Channel closed
}

After:

if sender.try_stream(Notification::ReorgDetected).await.is_closed() {
    return;
}

Testing

  • Added comprehensive tests for ChannelState enum
  • Added tests for TryStream trait behavior with open/closed channels

@0xNeshi
Copy link
Collaborator

0xNeshi commented Dec 5, 2025

Hi @yug49 thanks for contributing another PR!
As mentioned in the other PR, there may be a delay before we can thoroughly review your PRs.
Thank you once again!

@yug49
Copy link
Contributor Author

yug49 commented Dec 5, 2025

Sure, no problem

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.

Find Intuitive Design For Determining Whether Channel Was Closed in Nested Function Call

2 participants