pub struct GenericEventSubscriber<Event: DomainEvent> { /* private fields */ }Expand description
A generic event subscriber backed by a list of EventHandler implementations.
Event — the concrete event type (must implement DomainEvent)
Handlers are called in registration order. If an event type filter is set,
only events whose event_type() matches one of the registered types are dispatched.
Implementations§
Source§impl<Event: DomainEvent + Clone> GenericEventSubscriber<Event>
impl<Event: DomainEvent + Clone> GenericEventSubscriber<Event>
Sourcepub fn new(
subscribed_types: Vec<&'static str>,
handlers: Vec<Arc<dyn EventHandler<Event>>>,
) -> Self
pub fn new( subscribed_types: Vec<&'static str>, handlers: Vec<Arc<dyn EventHandler<Event>>>, ) -> Self
Create a subscriber with explicit type filters and handler list.
subscribed_types — filter to only these event_type() strings; empty = all.
handlers — ordered list of handlers to invoke.
Sourcepub fn all(handlers: Vec<Arc<dyn EventHandler<Event>>>) -> Self
pub fn all(handlers: Vec<Arc<dyn EventHandler<Event>>>) -> Self
Create a subscriber that receives all event types.
Sourcepub fn with_name(self, name: &'static str) -> Self
pub fn with_name(self, name: &'static str) -> Self
Override the subscriber name (used in logs).
Sourcepub fn with_handler(self, handler: Arc<dyn EventHandler<Event>>) -> Self
pub fn with_handler(self, handler: Arc<dyn EventHandler<Event>>) -> Self
Add a handler to the subscriber (builder pattern).
Sourcepub fn is_interested(&self, event_type: &str) -> bool
pub fn is_interested(&self, event_type: &str) -> bool
Returns true if this subscriber should receive the given event type.
Sourcepub async fn dispatch(&self, event: Event) -> Result<(), EventError>
pub async fn dispatch(&self, event: Event) -> Result<(), EventError>
Dispatch an event to all registered handlers in order.
The raw event is wrapped in an EventEnvelope before dispatch.
Returns on the first handler error.
Sourcepub fn subscribed_types(&self) -> &[&'static str]
pub fn subscribed_types(&self) -> &[&'static str]
The event types this subscriber handles (empty = all).
Sourcepub fn handler_count(&self) -> usize
pub fn handler_count(&self) -> usize
Number of registered handlers.