From 0071a4598a13d0c5ad6e82b1ab13c3a3facab31f Mon Sep 17 00:00:00 2001 From: Julia <30666851+ForLoveOfCats@users.noreply.github.com> Date: Thu, 1 Jun 2023 12:13:22 -0400 Subject: [PATCH] Avoid blocking forever on startup if config files do not exist (#2549) The files will still get created if the user opens their settings and saves, otherwise everything will transparently work Release Notes: - Fixed an issue where a missing settings file would cause a hang on startup ([#1590](https://github.com/zed-industries/community/issues/1590)). --- crates/settings/src/settings_file.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/settings/src/settings_file.rs b/crates/settings/src/settings_file.rs index cca2909da2..1a5ab2f922 100644 --- a/crates/settings/src/settings_file.rs +++ b/crates/settings/src/settings_file.rs @@ -55,15 +55,22 @@ pub fn watch_config_file( .spawn(async move { let events = fs.watch(&path, Duration::from_millis(100)).await; futures::pin_mut!(events); + + let contents = fs.load(&path).await.unwrap_or_default(); + if tx.unbounded_send(contents).is_err() { + return; + } + loop { + if events.next().await.is_none() { + break; + } + if let Ok(contents) = fs.load(&path).await { if !tx.unbounded_send(contents).is_ok() { break; } } - if events.next().await.is_none() { - break; - } } }) .detach();