mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-29 00:00:18 +02:00
document ws cancellation & delegation (#3786)
This commit is contained in:
@@ -549,11 +549,22 @@ impl WebSocket {
|
|||||||
/// Receive another message.
|
/// Receive another message.
|
||||||
///
|
///
|
||||||
/// Returns `None` if the stream has closed.
|
/// Returns `None` if the stream has closed.
|
||||||
|
///
|
||||||
|
/// This method delegates to [`Stream`].
|
||||||
|
///
|
||||||
|
/// # Cancel safety
|
||||||
|
///
|
||||||
|
/// This method is cancel safe. If used as a branch in [`tokio::select!`] and
|
||||||
|
/// another branch completes first, then no message is received.
|
||||||
|
///
|
||||||
|
/// [`tokio::select!`]: https://docs.rs/tokio/latest/tokio/macro.select.html
|
||||||
pub async fn recv(&mut self) -> Option<Result<Message, Error>> {
|
pub async fn recv(&mut self) -> Option<Result<Message, Error>> {
|
||||||
self.next().await
|
self.next().await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message.
|
/// Send a message.
|
||||||
|
///
|
||||||
|
/// This method delegates to [`Sink`].
|
||||||
pub async fn send(&mut self, msg: Message) -> Result<(), Error> {
|
pub async fn send(&mut self, msg: Message) -> Result<(), Error> {
|
||||||
self.inner
|
self.inner
|
||||||
.send(msg.into_tungstenite())
|
.send(msg.into_tungstenite())
|
||||||
|
|||||||
Reference in New Issue
Block a user