Return tasks from spawn and spawn_stream
Also, eliminate the background spawning methods. We can spawn futures on the executor and then spawn those on the app if we need to wait for the result of running one.
This commit is contained in:
@@ -62,18 +62,19 @@ impl Worktree {
|
||||
let tree = tree.clone();
|
||||
let (tx, rx) = smol::channel::bounded(1);
|
||||
|
||||
ctx.background_executor()
|
||||
.spawn(async move {
|
||||
tx.send(tree.scan_dirs()).await.unwrap();
|
||||
})
|
||||
.detach();
|
||||
let task = ctx.background_executor().spawn(async move {
|
||||
let _ = tx.send(tree.scan_dirs()?).await;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
let _ = ctx.spawn_local(async move { rx.recv().await.unwrap() }, Self::done_scanning);
|
||||
ctx.spawn(task, Self::done_scanning).detach();
|
||||
|
||||
let _ = ctx.spawn_stream_local(
|
||||
ctx.spawn_stream(
|
||||
timer::repeat(Duration::from_millis(100)).map(|_| ()),
|
||||
Self::scanning,
|
||||
);
|
||||
|_, _| {},
|
||||
)
|
||||
.detach();
|
||||
}
|
||||
|
||||
tree
|
||||
@@ -347,7 +348,7 @@ impl Worktree {
|
||||
}
|
||||
}
|
||||
|
||||
fn scanning(&mut self, _: Option<()>, ctx: &mut ModelContext<Self>) {
|
||||
fn scanning(&mut self, _: (), ctx: &mut ModelContext<Self>) {
|
||||
if self.0.read().scanning {
|
||||
ctx.notify();
|
||||
} else {
|
||||
@@ -356,6 +357,7 @@ impl Worktree {
|
||||
}
|
||||
|
||||
fn done_scanning(&mut self, result: io::Result<()>, ctx: &mut ModelContext<Self>) {
|
||||
log::info!("done scanning");
|
||||
self.0.write().scanning = false;
|
||||
if let Err(error) = result {
|
||||
log::error!("error populating worktree: {}", error);
|
||||
|
||||
Reference in New Issue
Block a user