diff --git a/src/lib.rs b/src/lib.rs index 2d956dd..69321fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -671,22 +671,16 @@ impl Recipient { /// frequently full (slow consumer), but would still like to be notified if a /// different error occurs (e.g. disconnection). pub fn send_if_not_full>(&self, message: N) -> Result<(), SendError> { - if self.remaining_capacity().unwrap_or(usize::max_value()) > 1 { - return self.send(message); - } - - Ok(()) + self.try_send(message).or_else(|err| match err { + SendError::Full => Ok(()), + other => Err(other), + }) } pub fn stop(&self) -> Result<(), SendError> { self.control_tx.send(Control::Stop).map_err(|_| SendError::Disconnected) } - // TODO(ryo): Properly support the concept of priority channels. - pub fn remaining_capacity(&self) -> Option { - self.message_tx.capacity().map(|capacity| capacity - self.message_tx.len()) - } - pub fn control_addr(&self) -> ControlAddr { ControlAddr { control_tx: self.control_tx.clone() } }