Refactors

This commit is contained in:
2026-10-03 15:56:29 +05:30
parent a3385e7702
commit c9438d00a6
14 changed files with 358 additions and 401 deletions
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "hd-examples"
version = "0.1.0"
edition = "2024"
[dependencies]
tracing = { workspace = true }
hd-lib = { path = "../hd-lib" }
hd-client = { path = "../hd-client" }
hd-server = { path = "../hd-server" }
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
+11
View File
@@ -0,0 +1,11 @@
use hd_client::{HdClient, HdClientError};
fn main() -> Result<(), HdClientError> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let addr = "0.0.0.0:21368";
let mut client = HdClient::start(addr)?;
client.subscribe()
}
+30
View File
@@ -0,0 +1,30 @@
use std::{sync::Arc, thread, time::Duration};
use hd_lib::{bus::EventData, error::HdError};
use hd_server::HdBus;
use tracing::info_span;
fn main() -> Result<(), HdError> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let addr = "0.0.0.0:21368";
let server = Arc::new(HdBus::new());
server.publish(EventData::new(1, "Hello"))?;
server.publish(EventData::new(1, "World"))?;
let server_clone = server.clone();
thread::spawn(move || {
let _scope = info_span!("tcp_server").entered();
server.start(addr)
});
let _scope = info_span!("health_checks").entered();
for i in 0..255 {
thread::sleep(Duration::from_secs(5));
server_clone.publish(EventData::new(i, "asd"))?;
}
Ok(())
}
View File