Files
heimdall/crates/hd-bus/src/bin/server.rs
T
2026-09-01 23:05:28 +05:30

27 lines
756 B
Rust

use std::{sync::Arc, thread, time::Duration};
use hd_bus::{TcpEventBus, bus::EventData, error::HError};
use tracing::info_span;
fn main() -> Result<(), HError> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let addr = "0.0.0.0:21368";
let _scope = info_span!("example_server").entered();
let server = Arc::new(TcpEventBus::new());
server.publish(EventData::new(1, "Hello"))?;
server.publish(EventData::new(1, "World"))?;
let server_clone = server.clone();
thread::spawn(move || server.start(addr));
for i in 0..255 {
thread::sleep(Duration::from_secs(5));
server_clone.publish(EventData::new(i, "asd"))?;
}
Ok(())
}