a3s_box_core/traits/event.rs
1//! Event bus abstraction.
2//!
3//! Decouples event emission and subscription from the Tokio broadcast
4//! channel implementation in `event.rs`. Implementations can use any
5//! pub/sub mechanism: in-process channels, NATS, Redis Pub/Sub, etc.
6//!
7//! The `BoxEvent` data type and event key constants remain in `event.rs`
8//! as pure data — this trait only abstracts the transport.
9
10use crate::event::BoxEvent;
11
12/// Abstraction over event emission.
13///
14/// The runtime emits events at key lifecycle points (box ready, exec
15/// completed, cache hit, etc.). Implementations decide how to deliver
16/// these events to subscribers.
17///
18/// # Thread Safety
19///
20/// Implementations must be `Send + Sync + Clone`. The runtime clones
21/// the bus and shares it across async tasks.
22pub trait EventBus: Send + Sync + Clone {
23 /// Emit an event to all subscribers.
24 ///
25 /// Fire-and-forget semantics — if no subscribers are listening,
26 /// the event is silently dropped.
27 fn emit(&self, event: BoxEvent);
28}
29
30/// Blanket impl: the existing `EventEmitter` already satisfies `EventBus`.
31impl EventBus for crate::event::EventEmitter {
32 fn emit(&self, event: BoxEvent) {
33 self.emit(event);
34 }
35}