From 0bb7189842aa8926e84fb3a166a5c6fa9f36e272 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 1 Mar 2022 17:08:10 +0100 Subject: [PATCH] Use a weak handle to poll local worktree snapshot Co-Authored-By: Nathan Sobo --- crates/project/src/worktree.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 3e2ad5ce20991316feda3006eb168b228803c7c4..33a564585acfaa71fbe154d1c0d33548c5234035 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -384,16 +384,18 @@ impl Worktree { worktree.snapshot = worktree.background_snapshot.lock().clone(); if worktree.is_scanning() { if worktree.poll_task.is_none() { - worktree.poll_task = Some(cx.spawn(|this, mut cx| async move { + worktree.poll_task = Some(cx.spawn_weak(|this, mut cx| async move { if is_fake_fs { cx.background().simulate_random_delay().await; } else { smol::Timer::after(Duration::from_millis(100)).await; } - this.update(&mut cx, |this, cx| { - this.as_local_mut().unwrap().poll_task = None; - this.poll_snapshot(cx); - }) + if let Some(this) = this.upgrade(&cx) { + this.update(&mut cx, |this, cx| { + this.as_local_mut().unwrap().poll_task = None; + this.poll_snapshot(cx); + }); + } })); } } else {