From 1a88444f2f52876eee4355a71cd7e6901850623b Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 21 Aug 2023 13:00:56 +0200 Subject: [PATCH] Increment job counter on JobClient::new Co-authored-by: Kyle --- crates/semantic_index/src/semantic_index.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/semantic_index/src/semantic_index.rs b/crates/semantic_index/src/semantic_index.rs index 7aea0f7cfe..4457f55b7c 100644 --- a/crates/semantic_index/src/semantic_index.rs +++ b/crates/semantic_index/src/semantic_index.rs @@ -103,6 +103,7 @@ struct JobHandle { impl JobHandle { fn new(tx: &Arc>>) -> Self { + *tx.lock().borrow_mut() += 1; Self { tx: Arc::new(Arc::downgrade(&tx)), } @@ -656,10 +657,8 @@ impl SemanticIndex { if !already_stored { count += 1; - *job_count_tx.lock().borrow_mut() += 1; - let job_handle = JobHandle { - tx: Arc::new(Arc::downgrade(&job_count_tx)), - }; + + let job_handle = JobHandle::new(&job_count_tx); parsing_files_tx .try_send(PendingFile { worktree_db_id: db_ids_by_worktree_id[&worktree.id()], @@ -865,8 +864,14 @@ mod tests { fn test_job_handle() { let (job_count_tx, job_count_rx) = watch::channel_with(0); let tx = Arc::new(Mutex::new(job_count_tx)); - let job_handle = JobHandle::new(tx); + let job_handle = JobHandle::new(&tx); - assert_eq!(1, *job_count_rx.borrow_mut()); + assert_eq!(1, *job_count_rx.borrow()); + let new_job_handle = job_handle.clone(); + assert_eq!(1, *job_count_rx.borrow()); + drop(job_handle); + assert_eq!(1, *job_count_rx.borrow()); + drop(new_job_handle); + assert_eq!(0, *job_count_rx.borrow()); } }