pub struct EventBus { /* private fields */ }Expand description
A broadcast-based event bus for the Punch system.
Cloning an EventBus yields a handle to the same underlying channel.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new event bus with a specific channel capacity.
Sourcepub fn publish(&self, event: PunchEvent)
pub fn publish(&self, event: PunchEvent)
Publish an event to all active subscribers.
The event is also stored in the history buffer for the audit trail.
Sourcepub fn publish_payload(&self, payload: EventPayload)
pub fn publish_payload(&self, payload: EventPayload)
Publish a pre-built EventPayload (useful when you need a custom
correlation ID or timestamp).
Sourcepub fn subscribe(&self) -> Receiver<EventPayload>
pub fn subscribe(&self) -> Receiver<EventPayload>
Subscribe to all future events on this bus.
Returns a broadcast::Receiver that will yield every event published
after the subscription is created. If the receiver falls behind by more
than the channel capacity, older events will be dropped and the receiver
will see a broadcast::error::RecvError::Lagged error.
Sourcepub fn subscribe_filtered<F>(&self, predicate: F) -> FilteredReceiver<F>
pub fn subscribe_filtered<F>(&self, predicate: F) -> FilteredReceiver<F>
Subscribe and return only events matching a predicate.
This is a convenience wrapper — filtering happens on the receiver side. For high-throughput scenarios consider filtering inside the subscriber’s own task loop instead.
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Return the current number of active subscribers.
Sourcepub fn recent_events(
&self,
limit: usize,
since: usize,
) -> Vec<(usize, EventPayload)>
pub fn recent_events( &self, limit: usize, since: usize, ) -> Vec<(usize, EventPayload)>
Return recent events from the history buffer.
Returns up to limit events, optionally filtering to only those with
a sequence (position) greater than since. Events are returned in
chronological order (oldest first).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventBus
impl !RefUnwindSafe for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl UnsafeUnpin for EventBus
impl !UnwindSafe for EventBus
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> 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 more