Document cancel-safety of StreamExt::next#2896
Document cancel-safety of StreamExt::next#2896akonradi-signal wants to merge 1 commit intorust-lang:masterfrom
Conversation
| /// # Cancel safety | ||
| /// | ||
| /// The returned future only holds a reference to the underlying stream, and | ||
| /// so is cancel safe (assuming the stream is also cancel-safe). If it is |
There was a problem hiding this comment.
assuming the stream is also cancel-safe
AFAIK, in the term "cancel-safe" used in tokio, cancel-safe is a property of Future and StreamExt::next is always cancel-safe. What is the definition of cancel-safe you are referring to?
https://docs.rs/tokio-stream/latest/tokio_stream/trait.StreamExt.html#method.next
There was a problem hiding this comment.
Good question. I'm drawing an analogy between Future::poll and Stream::poll_next, where calling the latter once but not until it returns Poll::Ready could lead to bad behavior.
The example I'm imagining is the result of calling StreamExt::chunks_timeout on a &mut impl Stream. Calling poll_once on that ChunksTimeout, then dropping it, then polling the wrapped stream could result in values from the input stream being dropped without ever being yielded. Given that possibility, I'd label ChunksTimeout not "cancel-safe".
Fixes #2701