Skip to content

Commit

Permalink
Temporary: Recipient: remove remaining_capacity(), implement send_if_…
Browse files Browse the repository at this point in the history
…not_full() differently

I expect that at least the second point will be resolved (more correctly) by #20.

Not sure whether we want to keep Recipient::remaining_capacity() or whether
it will be eventually superseded by #22.

This a temporary commit just to make prototyping of #11 easier.
  • Loading branch information
strohel committed Feb 25, 2021
1 parent 6e185d2 commit d1e38b6
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,22 +671,16 @@ impl<M> Recipient<M> {
/// 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<N: Into<M>>(&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<usize> {
self.message_tx.capacity().map(|capacity| capacity - self.message_tx.len())
}

pub fn control_addr(&self) -> ControlAddr {
ControlAddr { control_tx: self.control_tx.clone() }
}
Expand Down

0 comments on commit d1e38b6

Please sign in to comment.