Skip to content

Commit 753ca72

Browse files
authored
Document cancel safety of reading from WebSocketStream (#378)
Closes #359. Reading messages is cancel-safe because WebSocketStream exposes messages only through its Stream implementation, so reading via StreamExt::next inherits that trait's cancel-safety. This was confirmed in #359 but never landed in the rustdoc, so a user had to find the GitHub issue to learn it. Add a `# Cancel safety` section to the WebSocketStream docs stating the read guarantee, and note that the Sink (sending) side carries no documented guarantee. Co-authored-by: JustinCMR <JustinCMR@users.noreply.github.com>
1 parent 751d7e2 commit 753ca72

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ where
188188
/// through the respective `Stream` and `Sink`. Check more information about
189189
/// them in `futures-rs` crate documentation or have a look on the examples
190190
/// and unit tests for this crate.
191+
///
192+
/// # Cancel safety
193+
///
194+
/// Reading messages is cancel-safe. `WebSocketStream` has no dedicated read
195+
/// methods; messages arrive through its `Stream` implementation, and reading a
196+
/// message via `StreamExt::next` follows that trait's cancel-safety: if the
197+
/// `next()` future is dropped before it resolves (for example, as a branch of
198+
/// `tokio::select!` that another branch completes first), no message is lost.
199+
/// The next poll resumes from the same position in the stream.
200+
///
201+
/// The `Sink` side (sending) does not carry a documented cancel-safety
202+
/// guarantee.
191203
#[derive(Debug)]
192204
pub struct WebSocketStream<S> {
193205
inner: WebSocket<AllowStd<S>>,

0 commit comments

Comments
 (0)