use abxbus::{
event,
event_bus::EventBus,
BaseEvent,
};
use futures::executor::block_on;
use serde::{Deserialize, Serialize};
#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)]
struct OrderResult {
ok: bool,
}
event! {
struct OrderCreatedEvent {
order_id: String,
customer_id: String,
total_amount: f64,
event_result_type: OrderResult,
event_result_schema: r#"{
"type": "object",
"properties": {"ok": {"type": "boolean"}},
"required": ["ok"]
}"#,
}
}
let bus = EventBus::new(Some("OrdersBus".to_string()));
bus.on(OrderCreatedEvent, |event: OrderCreatedEvent| async move {
Ok(OrderResult {
ok: event.total_amount > 0.0,
})
});
let event = bus.emit(OrderCreatedEvent {
order_id: "order-123".to_string(),
customer_id: "customer-456".to_string(),
total_amount: 42.50,
..Default::default()
});
let typed_result = block_on(event.event_result())?
.expect("handler result");