From ff51be1a0bec3d3f2161215949aa6afec00d8e2c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 11 Jan 2022 20:26:06 -0500 Subject: move git calcuations to a background thread since it can be slow --- src/shell/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index b934f07..e2ccf2d 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -120,7 +120,10 @@ pub async fn main() -> anyhow::Result { async_std::task::spawn(async move { while watch_r.recv().await.is_ok() { let repo = git2::Repository::discover(&dir).ok(); - let info = repo.map(|repo| git::Info::new(&repo)); + let info = blocking::unblock(|| { + repo.map(|repo| git::Info::new(&repo)) + }) + .await; if event_w .send(Event::GitInfo(info)) .await @@ -134,7 +137,10 @@ pub async fn main() -> anyhow::Result { } else { _active_watcher = None; } - let info = repo.map(|repo| git::Info::new(&repo)); + let info = blocking::unblock(|| { + repo.map(|repo| git::Info::new(&repo)) + }) + .await; event_w.send(Event::GitInfo(info)).await.unwrap(); } }); -- cgit v1.2.3-54-g00ecf