Add ModelHandle::spawn_weak, fix worktree leak from spawn call

This commit is contained in:
Max Brunsfeld
2021-07-05 17:55:52 -07:00
parent 65e4e78cd7
commit 58eefcd331
2 changed files with 30 additions and 28 deletions
+10
View File
@@ -1761,6 +1761,16 @@ impl<'a, T: Entity> ModelContext<'a, T> {
let handle = self.handle();
self.app.spawn(|cx| f(handle, cx))
}
pub fn spawn_weak<F, Fut, S>(&self, f: F) -> Task<S>
where
F: FnOnce(WeakModelHandle<T>, AsyncAppContext) -> Fut,
Fut: 'static + Future<Output = S>,
S: 'static,
{
let handle = self.handle().downgrade();
self.app.spawn(|cx| f(handle, cx))
}
}
impl<M> AsRef<AppContext> for ModelContext<'_, M> {