Skip to content

Commit

Permalink
fix the hang
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Oct 9, 2023
1 parent 7cdd001 commit 3cf8112
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 3cf8112

Please sign in to comment.