From 238ce5e463f96a85866db30113b61fd1ea1e3870 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 17 Aug 2023 18:58:05 +0200 Subject: [PATCH] Delay opening browser and spawing local workers Creating the server might take quite a while if a fetch url is configured and no local repo is found. During this time the web server is not yet running, so the browser link and local workers would fail to connect and just show/log errors. --- src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6fed466..4f08128 100644 --- a/src/main.rs +++ b/src/main.rs @@ -167,16 +167,19 @@ async fn run() -> somehow::Result<()> { match args.command { Command::Server(command) => { info!("Starting server"); + let open = command.open; + let local_worker = command.local_worker; - if command.open { + let (server, recurring_rx) = Server::new(&config.server, command).await?; + + if open { tokio::task::spawn(open_in_browser(&config.server)); } - if command.local_worker > 0 { - tokio::task::spawn(launch_local_workers(config, command.local_worker)); + if local_worker > 0 { + tokio::task::spawn(launch_local_workers(config, local_worker)); } - let (server, recurring_rx) = Server::new(&config.server, command).await?; select! { _ = wait_for_signal() => {} _ = server.run(recurring_rx) => {}