From 869935dfc2a281f3c638c41812249390dbe78330 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 12 Apr 2024 12:58:07 +0100 Subject: [PATCH] fix(server): Prevent losing a task waker Closes kemitix/git-next#26 --- src/main.rs | 6 ++++-- src/server/mod.rs | 15 ++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index bd6718a..794dd5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,9 @@ enum Server { Init, Start, } -fn main() { + +#[actix_rt::main] +async fn main() { let fs = filesystem::FileSystem::new_real(None); let net = Network::new_real(); let commands = Commands::parse(); @@ -35,7 +37,7 @@ fn main() { server::init(fs); } Server::Start => { - server::start(fs, net); + server::start(fs, net).await; } }, } diff --git a/src/server/mod.rs b/src/server/mod.rs index dca5bdf..b9ff602 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -34,7 +34,7 @@ pub fn init(fs: FileSystem) { } } -pub fn start(fs: FileSystem, net: Network) { +pub async fn start(fs: FileSystem, net: Network) { let Ok(_) = init_logging() else { eprintln!("Failed to initialize logging."); return; @@ -49,17 +49,14 @@ pub fn start(fs: FileSystem, net: Network) { }; info!("Config loaded"); - let actors = config + let addresses = config .forges() .flat_map(|(forge_name, forge)| create_forge_repos(forge, forge_name, &net)) + .map(start_actor) .collect::>(); - - actix::System::new().block_on(async { - let addresses = actors.into_iter().map(start_actor).collect::>(); - let _ = actix_rt::signal::ctrl_c().await; - info!("Ctrl-C received, shutting down..."); - drop(addresses); - }); + let _ = actix_rt::signal::ctrl_c().await; + info!("Ctrl-C received, shutting down..."); + drop(addresses); } fn create_forge_repos(