pub struct EventManager { /* private fields */ }Expand description
Publisher side of the cluster events channel.
EventManager is cheap to clone (the inner
broadcast::Sender is reference-counted). Hand a clone or
an std::sync::Arc handle to every component that needs
to publish.
§Examples
use dynomite::events::EventManager;
let mgr = EventManager::new(8);
let _sub = mgr.subscribe();
assert_eq!(mgr.subscriber_count(), 1);Implementations§
Source§impl EventManager
impl EventManager
Sourcepub fn new(buffer: usize) -> Self
pub fn new(buffer: usize) -> Self
Build a fresh manager backed by a broadcast channel of the supplied capacity.
A capacity of zero is rejected by tokio; this constructor silently clamps it to one so embedding code does not have to special-case the empty value.
§Examples
use dynomite::events::EventManager;
let mgr = EventManager::new(64);
assert_eq!(mgr.subscriber_count(), 0);Sourcepub fn publish(&self, event: ClusterEvent)
pub fn publish(&self, event: ClusterEvent)
Publish an event to every live subscriber.
Returns silently when there are no subscribers attached;
tokio::sync::broadcast::Sender::send reports that case
as Err(SendError(_)), which we explicitly drop because
“no observers” is normal during quiet periods and is
never the publisher’s problem.
§Examples
use std::time::SystemTime;
use dynomite::events::{ClusterEvent, EventManager};
let mgr = EventManager::new(4);
// No subscribers attached; publish is still infallible.
mgr.publish(ClusterEvent::RingChanged {
tag: "init".into(),
ts: SystemTime::now(),
});Sourcepub fn subscribe(&self) -> Subscriber
pub fn subscribe(&self) -> Subscriber
Subscribe a fresh receiver.
Each call returns an independent Subscriber whose
queue starts empty; events published before the call are
not delivered to the new subscriber.
§Examples
use dynomite::events::EventManager;
let mgr = EventManager::new(4);
let _a = mgr.subscribe();
let _b = mgr.subscribe();
assert_eq!(mgr.subscriber_count(), 2);Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Number of attached subscribers.
Trait Implementations§
Source§impl Clone for EventManager
impl Clone for EventManager
Source§fn clone(&self) -> EventManager
fn clone(&self) -> EventManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EventManager
impl Debug for EventManager
Source§impl Default for EventManager
impl Default for EventManager
Source§fn default() -> Self
fn default() -> Self
Build a manager with a 64-event buffer.
64 matches the default capacity of crate::embed::events::EventBus
so embedders that swap one for the other do not see a
surprise change in lag behaviour.
Auto Trait Implementations§
impl Freeze for EventManager
impl !RefUnwindSafe for EventManager
impl Send for EventManager
impl Sync for EventManager
impl Unpin for EventManager
impl UnsafeUnpin for EventManager
impl !UnwindSafe for EventManager
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.