pub struct EventRouter { /* private fields */ }
Expand description
Core archivist internal event router that supports multiple event producers and multiple event consumers.
Implementations§
Source§impl EventRouter
impl EventRouter
Sourcepub fn add_producer<T>(&mut self, config: ProducerConfig<'_, T>)where
T: EventProducer,
pub fn add_producer<T>(&mut self, config: ProducerConfig<'_, T>)where
T: EventProducer,
Registers an event producer with the given configuration specifying the types of events the given producer is allowed to emit.
Sourcepub fn add_consumer<T>(&mut self, config: ConsumerConfig<'_, T>)
pub fn add_consumer<T>(&mut self, config: ConsumerConfig<'_, T>)
Registers an event consumer with the given configuration specifying the types of events the given consumer will receive.
Sourcepub fn start(
self,
) -> Result<(TerminateHandle, impl Future<Output = ()>), RouterError>
pub fn start( self, ) -> Result<(TerminateHandle, impl Future<Output = ()>), RouterError>
Starts listening for events emitted by the registered producers and dispatching them to registered consumers.
First, validates that for every event type that will be dispatched, there exists at least one consumer. And that for every event that will be consumed, there exists at least one producer.
Afterwards, listens to events emitted by producers. When an event arrives it sends it to all consumers of the event. Since all events are singletons, the first consumer that was registered will get the singleton data and the rest won’t.