Pass a handle to the current view model when spawning
Most of the time, we'll want a way to get a reference back to the current view or model, so this facilitates that common case.
This commit is contained in:
+6
-4
@@ -1654,11 +1654,12 @@ impl<'a, T: Entity> ModelContext<'a, T> {
|
||||
|
||||
pub fn spawn<F, Fut, S>(&self, f: F) -> Task<S>
|
||||
where
|
||||
F: FnOnce(AsyncAppContext) -> Fut,
|
||||
F: FnOnce(ModelHandle<T>, AsyncAppContext) -> Fut,
|
||||
Fut: 'static + Future<Output = S>,
|
||||
S: 'static,
|
||||
{
|
||||
self.app.spawn(f)
|
||||
let handle = self.handle();
|
||||
self.app.spawn(|ctx| f(handle, ctx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1909,11 +1910,12 @@ impl<'a, T: View> ViewContext<'a, T> {
|
||||
|
||||
pub fn spawn<F, Fut, S>(&self, f: F) -> Task<S>
|
||||
where
|
||||
F: FnOnce(AsyncAppContext) -> Fut,
|
||||
F: FnOnce(ViewHandle<T>, AsyncAppContext) -> Fut,
|
||||
Fut: 'static + Future<Output = S>,
|
||||
S: 'static,
|
||||
{
|
||||
self.app.spawn(f)
|
||||
let handle = self.handle();
|
||||
self.app.spawn(|ctx| f(handle, ctx))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user