Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aegis-runtime-mv/blob/main/src/events/bus.rs # aegis-runtime-mv Native Rust agent runtime: Axum WebSocket/SSE/REST gateway, heartbeat scheduler, dependency-aware task workflow, SQLite storage. Attachment of AienOS. Pre-alpha. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aegis-runtime-mv / src / events / bus.rs` 38 lines ยท 925 bytes Raw Blame History 1 use super::envelope::EventEnvelope; 2 use async_trait::async_trait; 3 use tokio::sync::broadcast; 4 5 pub const DEFAULT_BUS_CAPACITY: usize = 1024; 6 7 #[derive(Clone)] 8 pub struct EventBus { 9 sender: broadcast::Sender, 10 } 11 12 impl Default for EventBus { 13 fn default() -> Self { 14 Self::new(DEFAULT_BUS_CAPACITY) 15 } 16 } 17 18 impl EventBus { 19 pub fn new(capacity: usize) -> Self { 20 let (sender, _) = broadcast::channel(capacity); 21 Self { sender } 22 } 23 24 pub fn publish(&self, envelope: EventEnvelope) -> Result { 25 self.sender 26 .send(envelope) 27 .map_err(|e| format!("Failed to publish event: {}", e)) 28 } 29 30 pub fn subscribe(&self) -> broadcast::Receiver { 31 self.sender.subscribe() 32 } 33 } 34 35 #[async_trait] 36 pub trait EventSubscriber: Send + Sync { 37 async fn on_event(&self, envelope: &EventEnvelope) -> Result<(), String>; 38 }