|
|
|
@ -5,27 +5,27 @@ use crate::message::Message;
@@ -5,27 +5,27 @@ use crate::message::Message;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq)] |
|
|
|
|
#[non_exhaustive] |
|
|
|
|
pub enum RecvError { |
|
|
|
|
pub enum SubscriptionError { |
|
|
|
|
Empty, |
|
|
|
|
Closed, |
|
|
|
|
Lagged, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<broadcast::error::RecvError> for RecvError { |
|
|
|
|
impl From<broadcast::error::RecvError> for SubscriptionError { |
|
|
|
|
fn from(err: broadcast::error::RecvError) -> Self { |
|
|
|
|
match err { |
|
|
|
|
broadcast::error::RecvError::Closed => RecvError::Closed, |
|
|
|
|
broadcast::error::RecvError::Lagged(_) => RecvError::Lagged, |
|
|
|
|
broadcast::error::RecvError::Closed => SubscriptionError::Closed, |
|
|
|
|
broadcast::error::RecvError::Lagged(_) => SubscriptionError::Lagged, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<broadcast::error::TryRecvError> for RecvError { |
|
|
|
|
impl From<broadcast::error::TryRecvError> for SubscriptionError { |
|
|
|
|
fn from(err: broadcast::error::TryRecvError) -> Self { |
|
|
|
|
match err { |
|
|
|
|
broadcast::error::TryRecvError::Empty => RecvError::Empty, |
|
|
|
|
broadcast::error::TryRecvError::Closed => RecvError::Closed, |
|
|
|
|
broadcast::error::TryRecvError::Lagged(_) => RecvError::Lagged, |
|
|
|
|
broadcast::error::TryRecvError::Empty => SubscriptionError::Empty, |
|
|
|
|
broadcast::error::TryRecvError::Closed => SubscriptionError::Closed, |
|
|
|
|
broadcast::error::TryRecvError::Lagged(_) => SubscriptionError::Lagged, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -42,15 +42,15 @@ impl<T> Subscription<T> {
@@ -42,15 +42,15 @@ impl<T> Subscription<T> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl<T: Message> Subscription<T> { |
|
|
|
|
pub async fn recv(&mut self) -> Result<T, RecvError> { |
|
|
|
|
pub async fn recv(&mut self) -> Result<T, SubscriptionError> { |
|
|
|
|
Ok(self.receiver.recv().await?) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn recv_blocking(&mut self) -> Result<T, RecvError> { |
|
|
|
|
pub fn recv_blocking(&mut self) -> Result<T, SubscriptionError> { |
|
|
|
|
block_on(self.recv()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn try_recv(&mut self) -> Result<T, RecvError> { |
|
|
|
|
pub fn try_recv(&mut self) -> Result<T, SubscriptionError> { |
|
|
|
|
Ok(self.receiver.try_recv()?) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|