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.
If there are no subscribers the event is silently dropped.
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.