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)));