Skip to main content

roboticus_pipeline/
event_bus.rs

1//! Pipeline progress event bus.
2//!
3//! A simple broadcast channel for pipeline stages to emit progress
4//! events (classification, memory assessment, planner decisions) that
5//! are consumed by the WebSocket layer in roboticus-api.
6
7use 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}