cassette icon indicating copy to clipboard operation
cassette copied to clipboard

Polling a done future

Open mbuesch opened this issue 3 years ago • 4 comments

Hi,

I'm wondering what the reasons behind this TODO are: https://github.com/jamesmunns/cassette/blob/main/src/lib.rs#L341

I currently have a use case where I want to poll a future that becomes read every now and then. That is a problem with cassette, because

  • Cassette::new consumes the future and there's currently no way to retrieve it back (into_inner).
  • poll_on refuses to work if it was ready once.

My current workaround is that I have a wrapper future around my actual future and I re-create the Cassette with the wrapper every time it becomes ready. That works, but is less than optimal, though. I do not want to re-create the actual future that I'm polling, because that has side effects.

Therefore, what are the options for a Cassette change? How could this todo!() be removed? If not, would it be acceptable, if an unwrap (consuming into_inner) would be added to retrieve the future, so that I can re-create the Cassette with the same future?

Thanks in advance.

mbuesch avatar May 01 '21 18:05 mbuesch

What's your usecase? A future shouldn't become ready every now and then, it should become ready exactly once; reason is that it has to produce a value at some point, and it shouldn't have to produce the value repeatedly.

Your usecase sounds more as if it should utilize something like tokio's streams.

Finomnis avatar Nov 25 '23 20:11 Finomnis

It even is a direct violation of the poll() function:

Once a future has finished, clients should not poll it again.

Finomnis avatar Dec 22 '23 00:12 Finomnis

The question was: Why is it a TODO? If this is so clearly defined, then this should be a panic instead.

mbuesch avatar Dec 22 '23 07:12 mbuesch

The question was: Why is it a TODO? If this is so clearly defined, then this should be a panic instead.

I agree.

Finomnis avatar Dec 22 '23 07:12 Finomnis