reorganized to stop the race

This commit is contained in:
KCaverly 2023-08-22 15:01:21 +02:00
parent aabdfa210f
commit 328b7e523c

View file

@ -685,17 +685,19 @@ impl SemanticIndex {
let (job_count_tx, job_count_rx) = watch::channel_with(0); let (job_count_tx, job_count_rx) = watch::channel_with(0);
let job_count_tx = Arc::new(Mutex::new(job_count_tx)); let job_count_tx = Arc::new(Mutex::new(job_count_tx));
this.update(&mut cx, |this, _| { let job_count_tx_longlived = job_count_tx.clone();
let project_state = ProjectState::new( // this.update(&mut cx, |this, _| {
_subscription, // let project_state = ProjectState::new(
worktree_db_ids, // _subscription,
worktree_file_mtimes.clone(), // worktree_db_ids,
job_count_rx.clone(), // worktree_file_mtimes.clone(),
job_count_tx.clone(), // job_count_rx.clone(),
); // job_count_tx.clone(),
this.projects.insert(project.downgrade(), project_state); // );
}); // this.projects.insert(project.downgrade(), project_state);
// });
let worktree_file_mtimes_all = worktree_file_mtimes.clone();
let worktree_files = cx let worktree_files = cx
.background() .background()
.spawn(async move { .spawn(async move {
@ -750,6 +752,14 @@ impl SemanticIndex {
.await?; .await?;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let project_state = ProjectState::new(
_subscription,
worktree_db_ids,
worktree_file_mtimes_all,
job_count_rx,
job_count_tx_longlived,
);
if let Some(project_state) = this.projects.get_mut(&project.downgrade()) { if let Some(project_state) = this.projects.get_mut(&project.downgrade()) {
for (worktree_id, index_operations) in &worktree_files { for (worktree_id, index_operations) in &worktree_files {
for op in index_operations { for op in index_operations {
@ -757,6 +767,8 @@ impl SemanticIndex {
} }
} }
} }
this.projects.insert(project.downgrade(), project_state);
}); });
cx.background().spawn(async move { anyhow::Ok(()) }).await cx.background().spawn(async move { anyhow::Ok(()) }).await