pub struct Subscriber { /* private fields */ }Expand description
Receive side of the cluster events channel.
Construct via super::EventManager::subscribe. Multiple
subscribers are independent: each receives its own copy of
every event published after the subscribe call.
Implementations§
Source§impl Subscriber
impl Subscriber
Sourcepub async fn recv(&mut self) -> Result<ClusterEvent, SubscriberError>
pub async fn recv(&mut self) -> Result<ClusterEvent, SubscriberError>
Await the next event.
Returns SubscriberError::Closed when the upstream
super::EventManager has been dropped, and
SubscriberError::Lagged if the receiver fell behind
the channel tail. After SubscriberError::Lagged, the
subscriber is still usable; the next call resumes from
the freshest event in the buffer.
§Examples
use std::time::SystemTime;
use dynomite::events::{ClusterEvent, EventManager};
let mgr = EventManager::new(4);
let mut sub = mgr.subscribe();
mgr.publish(ClusterEvent::RingChanged {
tag: "x".into(),
ts: SystemTime::now(),
});
let evt = sub.recv().await.unwrap();
assert!(matches!(evt, ClusterEvent::RingChanged { .. }));Sourcepub fn try_recv(&mut self) -> Result<ClusterEvent, TryRecvError>
pub fn try_recv(&mut self) -> Result<ClusterEvent, TryRecvError>
Non-blocking poll for the next event.
Returns TryRecvError::Empty when no event is yet
available, TryRecvError::Closed when the upstream
manager has been dropped and the buffer drained, and
TryRecvError::Lagged if the receiver fell behind the
channel tail.
§Examples
use dynomite::events::{EventManager, TryRecvError};
let mgr = EventManager::new(4);
let mut sub = mgr.subscribe();
assert!(matches!(sub.try_recv(), Err(TryRecvError::Empty)));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Subscriber
impl !RefUnwindSafe for Subscriber
impl Send for Subscriber
impl Sync for Subscriber
impl Unpin for Subscriber
impl UnsafeUnpin for Subscriber
impl !UnwindSafe for Subscriber
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.