futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

futures-channel: ensure `is_terminated()` reflects the state of the channel

Open petrosagg opened this issue 3 months ago • 0 comments

I noticed that is_terminated() returns true only after a None value has been observed from the stream. The documentation ofFusedStream allows this method to return true earlier, if the stream can no longer make progress:

Usually, this state occurs after poll_next (or try_poll_next) returned Poll::Ready(None). However, is_terminated may also return true if a stream has become inactive and can no longer make progress and should be ignored or dropped rather than being polled again.

This PR was prompted by a use case that wants to see if the channel has more things to give out without actually pulling them out of the stream since the place of checking is not the right place to handle a potential element from the stream.

This effectively makes .is_terminated() behave like tokio::sync::mpsc::UnboundedReceiver::is_closed().

petrosagg avatar Sep 16 '25 14:09 petrosagg