roboticus_pipeline/
event_bus.rs1use tokio::sync::broadcast;
8
9#[derive(Clone)]
10pub struct EventBus {
11 tx: broadcast::Sender<String>,
12}
13
14impl EventBus {
15 pub fn new(capacity: usize) -> Self {
16 let (tx, _) = broadcast::channel(capacity);
17 Self { tx }
18 }
19
20 pub fn publish(&self, event: String) {
21 if let Err(e) = self.tx.send(event) {
22 tracing::debug!(error = %e, "EventBus publish: no active subscribers");
23 }
24 }
25
26 pub fn subscribe(&self) -> broadcast::Receiver<String> {
27 self.tx.subscribe()
28 }
29}