Add a method for waiting until a worktree's current scan is complete

Start removing usages of finish_pending_tasks in tests
This commit is contained in:
Max Brunsfeld
2021-04-19 17:45:01 -07:00
parent 8fb79a3094
commit 69a43afcbd
4 changed files with 53 additions and 7 deletions
+15 -1
View File
@@ -94,6 +94,19 @@ impl Workspace {
&self.worktrees
}
pub fn worktree_scans_complete(&self, ctx: &AppContext) -> impl Future<Output = ()> + 'static {
let futures = self
.worktrees
.iter()
.map(|worktree| worktree.read(ctx).scan_complete())
.collect::<Vec<_>>();
async move {
for future in futures {
future.await;
}
}
}
pub fn contains_paths(&self, paths: &[PathBuf], app: &AppContext) -> bool {
paths.iter().all(|path| self.contains_path(&path, app))
}
@@ -235,7 +248,8 @@ mod tests {
}));
let workspace = app.add_model(|ctx| Workspace::new(vec![dir.path().into()], ctx));
app.finish_pending_tasks().await; // Open and populate worktree.
app.read(|ctx| workspace.read(ctx).worktree_scans_complete(ctx))
.await;
// Get the first file entry.
let tree = app.read(|ctx| workspace.read(ctx).worktrees.iter().next().unwrap().clone());
+2 -1
View File
@@ -393,7 +393,8 @@ mod tests {
let settings = settings::channel(&app.font_cache()).unwrap().1;
let workspace = app.add_model(|ctx| Workspace::new(vec![dir.path().into()], ctx));
app.finish_pending_tasks().await; // Open and populate worktree.
app.read(|ctx| workspace.read(ctx).worktree_scans_complete(ctx))
.await;
let entries = app.read(|ctx| workspace.file_entries(ctx));
let (_, workspace_view) =