From 3cf8112437937fb1f111820a675d6a53e649e841 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 9 Oct 2023 17:01:23 -0400 Subject: [PATCH] fix the hang --- src/app/state.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/app/state.rs b/src/app/state.rs index ff0ba851..24ea95cb 100644 --- a/src/app/state.rs +++ b/src/app/state.rs @@ -49,11 +49,17 @@ impl AppState { #[instrument(name = "update-nix-info", skip(self))] pub async fn update_nix_info(&self) { tracing::info!("Updating nix info ..."); - let nix_info = nix_rs::info::NixInfo::from_nix(&nix_rs::command::NixCmd::default()) - .await - .map_err(|e| SystemError { - message: format!("Error getting nix info: {:?}", e), - }); + // NOTE: Without tokio::spawn, this will run in main desktop thread, + // and will hang at some point. + let nix_info = tokio::spawn(async move { + nix_rs::info::NixInfo::from_nix(&nix_rs::command::NixCmd::default()) + .await + .map_err(|e| SystemError { + message: format!("Error getting nix info: {:?}", e), + }) + }) + .await + .unwrap(); tracing::info!("Got nix info, about to mut"); self.nix_info.with_mut(move |x| { *x = Some(nix_info); @@ -64,9 +70,13 @@ impl AppState { #[instrument(name = "update-nix-env", skip(self))] pub async fn update_nix_env(&self) { tracing::info!("Updating nix env ..."); - let nix_env = nix_rs::env::NixEnv::detect(None) - .await - .map_err(|e| e.to_string().into()); + let nix_env = tokio::spawn(async move { + nix_rs::env::NixEnv::detect(None) + .await + .map_err(|e| e.to_string().into()) + }) + .await + .unwrap(); tracing::info!("Got nix env, about to mut"); self.nix_env.with_mut(move |x| { *x = Some(nix_env);