Macro ruva_core::init_event_handler
source · macro_rules! init_event_handler { ( $E:ty, $event_handler :expr, $( $(#[$asynchrony:ident])? $event:ty:[$($handler:ident $(=>($($injectable:ident $(( $($arg:ident),* ))? ),*))?),* $(,)? ] ),* $(,)? ) => { ... }; ( $Bus:ident, $E:ty, $event_handler :expr, $( $(#[$asynchrony:ident])? $event:ty:[$($handler:ident $(=>($($injectable:ident $(( $($arg:ident),* ))? ),*))?),* $(,)? ] ),* $(,)? ) => { ... }; }
Expand description
This macro is used to create event handler for each event.
§Example
impl ruva::TEventBus<YourServiceError> for CustomBus{
fn event_handler(&self) -> &'static ruva::TEventHandler<$E>{
// EVENT_HANDLERS is a static variable that holds all event handlers. this will be automatically generated by the macro below.
&EVENT_HANDLERS
}
}
init_event_handler!(
YourServiceError,
|ctx| YourEventHandler(ApplicationRepository::new(ctx)),
#[asynchronous]
YourEvent:[handler1, handler2],
#[synchronous]
YourEvent2:[handler3, handler4],
);If you pass bus, ruva::TEventBus will be implemented for you.
§Example
init_event_handler!(
CustomBus,
YourServiceResponse,
YourServiceError,
|ctx| YourEventHandler(ApplicationRepository::new(ctx)),
#[asynchronous]
YourEvent:[handler1, handler2],
#[synchronous]
YourEvent2:[handler3, handler4],
);