#[cfg(all(feature = "tokio", feature = "config-watch"))]
use proc_daemon::{Config, Daemon};
#[cfg(all(feature = "tokio", feature = "config-watch"))]
#[tokio::main]
async fn main() -> proc_daemon::Result<()> {
let config = Config::builder()
.name("hot-reload-demo")
.hot_reload(true)
.build()?;
let daemon = Daemon::builder(config)
.with_task("noop", |_shutdown| async { Ok(()) })
.build()?;
let observer = daemon.clone();
tokio::spawn(async move {
loop {
let cfg = observer.config_snapshot();
tracing::info!(
name = %cfg.name,
json_logging = %cfg.is_json_logging(),
worker_threads = %cfg.performance.worker_threads,
"Observed live config snapshot"
);
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
}
});
daemon.run().await
}
#[cfg(not(all(feature = "tokio", feature = "config-watch")))]
fn main() {
eprintln!(
"This example requires features: tokio + config-watch (optionally: toml mmap-config)."
);
}