diff --git a/src/main.rs b/src/main.rs index 6957c4cdd..7789aa31a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ -use std::{process::exit, sync::Arc, thread}; +use std::{process::exit, sync::Arc}; use axolotl::handlers::Handler; use futures::lock::Mutex; -use presage::{MigrationConflictStrategy, SledStore}; use warp::{Filter, Rejection, Reply}; use clap::Parser; @@ -22,30 +21,24 @@ async fn main() { .parse_env("debug") .init(); let args = Args::parse(); - thread::spawn(|| { - let rt = tokio::runtime::Runtime::new().unwrap(); - rt.block_on(async move { - let mut handler: Handler = match Handler::new().await { - Ok(h) => h, - Err(e) => { - log::error!("Error while starting the server: {}", e); - exit(1); - } - }; - let handler_mutex = Arc::new(Mutex::new(Some(handler))); - start_websocket(handler_mutex.clone()).await; + let server_task = tokio::spawn(async { + let handler = Handler::new().await.unwrap_or_else(|e| { + log::error!("Error while starting the server: {}", e); + exit(1); }); + let handler_mutex = Arc::new(Mutex::new(Some(handler))); + start_websocket(handler_mutex).await; }); + if args.deamon { - log::info!("Starting the deamon"); - loop { - std::thread::sleep(std::time::Duration::from_secs(1)); - } + log::info!("Starting the daemon"); } else { log::info!("Starting the client"); start_ui().await; } + + server_task.await.unwrap(); } async fn start_websocket(handler: Arc>>) {