Skip to content

Commit

Permalink
Simplify main function
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnius committed Feb 5, 2023
1 parent 734584a commit 29e6ed3
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<futures::lock::Mutex<Option<Handler>>>) {
Expand Down

0 comments on commit 29e6ed3

Please sign in to comment.