cassette
cassette copied to clipboard
Polling a done future
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.
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.
It even is a direct violation of the poll() function:
Once a future has finished, clients should not poll it again.
The question was: Why is it a TODO? If this is so clearly defined, then this should be a panic instead.
The question was: Why is it a TODO? If this is so clearly defined, then this should be a panic instead.
I agree.