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

Adds unbonded select

Open CJP10 opened this issue 5 years ago • 3 comments

In a project I am working on I need the stream returned from select to close if either of the input streams are closed.

I figured this would be useful to someone else, so here I am.

I'm not sure about the name unbonded but I'm totally open to suggestions.

CJP10 avatar Sep 22 '19 03:09 CJP10

@CJP10 This would be very useful for me! I'd love to see this merged. Surprised nobody else has needed this.

Looks like this needs to be updated to work with SelectWithStrategy. Not sure what the ideal semantics should be exactly, but at a brief glance, it looks like maybe PollNext could be generalized to have a Nothing option, to prevent future polling?

@taiki-e, if this code is updated and polished, would you be open to accepting the feature, and merging?

I'm not sure about the name unbonded but I'm totally open to suggestions.

How about select_short_circuit, or select_until_either_terminates?


As for my use case, I have a stream of data that's being written to a tcp socket, with long waits between elements, and I have a stream representing a heartbeat to keep the connection alive. I don't want to keep sending heartbeats once the data stream terminates.

414owen avatar Mar 19 '22 18:03 414owen

Similar to my use case. I'm open to refreshing the PR to be mergeable. It's be open for a while so might have to start from scratch.

CJP10 avatar Mar 24 '22 03:03 CJP10

@CJP10 I've drafted something here: https://github.com/414owen/futures-rs/pull/1 It builds on https://github.com/rust-lang/futures-rs/pull/2583, so any reviews on that would be appreciated too!

414owen avatar Mar 25 '22 16:03 414owen