Update old usages of ctx.spawn
to detach the associated task
This lets us open buffers and renders tabs and editors correctly, modulo a small bug when rendering the gutter that I am going to fix next.
This commit is contained in:
parent
13c1f5f60e
commit
2c24ec2e46
3 changed files with 18 additions and 12 deletions
|
@ -38,16 +38,18 @@ impl<T> Receiver<T> {
|
||||||
impl<T: 'static + Clone> Receiver<T> {
|
impl<T: 'static + Clone> Receiver<T> {
|
||||||
pub fn notify_model_on_change<M: 'static + Entity>(&self, ctx: &mut ModelContext<M>) {
|
pub fn notify_model_on_change<M: 'static + Entity>(&self, ctx: &mut ModelContext<M>) {
|
||||||
let watch = self.clone();
|
let watch = self.clone();
|
||||||
let _ = ctx.spawn(async move { watch.updated().await }, |_, _, ctx| {
|
ctx.spawn(async move { watch.updated().await }, |_, _, ctx| {
|
||||||
ctx.notify()
|
ctx.notify()
|
||||||
});
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notify_view_on_change<V: 'static + View>(&self, ctx: &mut ViewContext<V>) {
|
pub fn notify_view_on_change<V: 'static + View>(&self, ctx: &mut ViewContext<V>) {
|
||||||
let watch = self.clone();
|
let watch = self.clone();
|
||||||
let _ = ctx.spawn(async move { watch.updated().await }, |_, _, ctx| {
|
ctx.spawn(async move { watch.updated().await }, |_, _, ctx| {
|
||||||
ctx.notify()
|
ctx.notify()
|
||||||
});
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,29 +161,32 @@ impl Workspace {
|
||||||
|
|
||||||
let (mut tx, rx) = watch::channel(None);
|
let (mut tx, rx) = watch::channel(None);
|
||||||
self.items.insert(entry, OpenedItem::Loading(rx));
|
self.items.insert(entry, OpenedItem::Loading(rx));
|
||||||
let _ = ctx.spawn(
|
ctx.spawn(
|
||||||
buffer,
|
buffer,
|
||||||
move |me, buffer: anyhow::Result<Buffer>, ctx| match buffer {
|
move |me, buffer: anyhow::Result<Buffer>, ctx| match buffer {
|
||||||
Ok(buffer) => {
|
Ok(buffer) => {
|
||||||
let handle = Box::new(ctx.add_model(|_| buffer)) as Box<dyn ItemHandle>;
|
let handle = Box::new(ctx.add_model(|_| buffer)) as Box<dyn ItemHandle>;
|
||||||
me.items.insert(entry, OpenedItem::Loaded(handle.clone()));
|
me.items.insert(entry, OpenedItem::Loaded(handle.clone()));
|
||||||
let _ = ctx.spawn(
|
ctx.spawn(
|
||||||
async move {
|
async move {
|
||||||
tx.update(|value| *value = Some(Ok(handle))).await;
|
tx.update(|value| *value = Some(Ok(handle))).await;
|
||||||
},
|
},
|
||||||
|_, _, _| {},
|
|_, _, _| {},
|
||||||
);
|
)
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
let _ = ctx.spawn(
|
ctx.spawn(
|
||||||
async move {
|
async move {
|
||||||
tx.update(|value| *value = Some(Err(Arc::new(error)))).await;
|
tx.update(|value| *value = Some(Err(Arc::new(error)))).await;
|
||||||
},
|
},
|
||||||
|_, _, _| {},
|
|_, _, _| {},
|
||||||
);
|
)
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
)
|
||||||
|
.detach();
|
||||||
|
|
||||||
self.open_entry(entry, ctx)
|
self.open_entry(entry, ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ impl WorkspaceView {
|
||||||
Err(error) => error!("{}", error),
|
Err(error) => error!("{}", error),
|
||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
let settings = self.settings.clone();
|
let settings = self.settings.clone();
|
||||||
let _ = ctx.spawn(item, move |me, item, ctx| {
|
ctx.spawn(item, move |me, item, ctx| {
|
||||||
me.loading_entries.remove(&entry);
|
me.loading_entries.remove(&entry);
|
||||||
match item {
|
match item {
|
||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
|
@ -187,7 +187,8 @@ impl WorkspaceView {
|
||||||
error!("{}", error);
|
error!("{}", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue