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:
@@ -1066,7 +1066,7 @@ impl BufferView {
|
||||
ctx.notify();
|
||||
|
||||
let epoch = self.next_blink_epoch();
|
||||
let _ = ctx.spawn_local(
|
||||
let _ = ctx.spawn(
|
||||
async move {
|
||||
Timer::after(CURSOR_BLINK_INTERVAL).await;
|
||||
epoch
|
||||
@@ -1088,7 +1088,7 @@ impl BufferView {
|
||||
ctx.notify();
|
||||
|
||||
let epoch = self.next_blink_epoch();
|
||||
let _ = ctx.spawn_local(
|
||||
let _ = ctx.spawn(
|
||||
async move {
|
||||
Timer::after(CURSOR_BLINK_INTERVAL).await;
|
||||
epoch
|
||||
|
||||
+2
-2
@@ -38,14 +38,14 @@ impl<T> Receiver<T> {
|
||||
impl<T: 'static + Clone> Receiver<T> {
|
||||
pub fn notify_model_on_change<M: 'static + Entity>(&self, ctx: &mut ModelContext<M>) {
|
||||
let watch = self.clone();
|
||||
let _ = ctx.spawn_local(async move { watch.updated().await }, |_, _, ctx| {
|
||||
let _ = ctx.spawn(async move { watch.updated().await }, |_, _, ctx| {
|
||||
ctx.notify()
|
||||
});
|
||||
}
|
||||
|
||||
pub fn notify_view_on_change<V: 'static + View>(&self, ctx: &mut ViewContext<V>) {
|
||||
let watch = self.clone();
|
||||
let _ = ctx.spawn_local(async move { watch.updated().await }, |_, _, ctx| {
|
||||
let _ = ctx.spawn(async move { watch.updated().await }, |_, _, ctx| {
|
||||
ctx.notify()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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