Skip to content

Commit af32517

Browse files
authored
Merge pull request #15 from n0-computer/Frando/fix-try-send
fix: Sender::try_send should return whether the item was sent
2 parents 4aca16f + 6fbb4e3 commit af32517

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,16 @@ pub mod channel {
464464
/// all.
465465
///
466466
/// Returns true if the message was sent.
467-
pub async fn try_send(&mut self, value: T) -> std::result::Result<(), SendError> {
467+
pub async fn try_send(&mut self, value: T) -> std::result::Result<bool, SendError> {
468468
match self {
469469
Sender::Tokio(tx) => match tx.try_send(value) {
470-
Ok(()) => Ok(()),
470+
Ok(()) => Ok(true),
471471
Err(tokio::sync::mpsc::error::TrySendError::Closed(_)) => {
472472
Err(SendError::ReceiverClosed)
473473
}
474-
Err(tokio::sync::mpsc::error::TrySendError::Full(_)) => Ok(()),
474+
Err(tokio::sync::mpsc::error::TrySendError::Full(_)) => Ok(false),
475475
},
476-
Sender::Boxed(sink) => {
477-
sink.try_send(value).await.map_err(SendError::from)?;
478-
Ok(())
479-
}
476+
Sender::Boxed(sink) => sink.try_send(value).await.map_err(SendError::from),
480477
}
481478
}
482479
}

0 commit comments

Comments
 (0)