From 6fbb4e3a964e200bfaa90a49bd4902df4bad6538 Mon Sep 17 00:00:00 2001 From: Frando Date: Tue, 6 May 2025 14:28:16 +0200 Subject: [PATCH] fix: Sender::try_send should return whether the item was sent --- src/lib.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 46b5f56..9198eef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -464,19 +464,16 @@ pub mod channel { /// all. /// /// Returns true if the message was sent. - pub async fn try_send(&mut self, value: T) -> std::result::Result<(), SendError> { + pub async fn try_send(&mut self, value: T) -> std::result::Result { match self { Sender::Tokio(tx) => match tx.try_send(value) { - Ok(()) => Ok(()), + Ok(()) => Ok(true), Err(tokio::sync::mpsc::error::TrySendError::Closed(_)) => { Err(SendError::ReceiverClosed) } - Err(tokio::sync::mpsc::error::TrySendError::Full(_)) => Ok(()), + Err(tokio::sync::mpsc::error::TrySendError::Full(_)) => Ok(false), }, - Sender::Boxed(sink) => { - sink.try_send(value).await.map_err(SendError::from)?; - Ok(()) - } + Sender::Boxed(sink) => sink.try_send(value).await.map_err(SendError::from), } } }