WIP
This commit is contained in:
@@ -504,16 +504,12 @@ impl AppContext {
|
||||
|
||||
/// Spawns the future returned by the given function on the thread pool. The closure will be invoked
|
||||
/// with AsyncAppContext, which allows the application state to be accessed across await points.
|
||||
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut + Send + 'static) -> Task<R>
|
||||
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R>
|
||||
where
|
||||
Fut: Future<Output = R> + Send + 'static,
|
||||
R: Send + 'static,
|
||||
{
|
||||
let cx = self.to_async();
|
||||
self.executor.spawn(async move {
|
||||
let future = f(cx);
|
||||
future.await
|
||||
})
|
||||
self.executor.spawn(f(self.to_async()))
|
||||
}
|
||||
|
||||
/// Schedules the given function to be run at the end of the current effect cycle, allowing entities
|
||||
|
||||
@@ -189,10 +189,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn spawn<Fut, R>(
|
||||
&self,
|
||||
f: impl FnOnce(WeakModel<T>, AsyncAppContext) -> Fut + Send + 'static,
|
||||
) -> Task<R>
|
||||
pub fn spawn<Fut, R>(&self, f: impl FnOnce(WeakModel<T>, AsyncAppContext) -> Fut) -> Task<R>
|
||||
where
|
||||
T: 'static,
|
||||
Fut: Future<Output = R> + Send + 'static,
|
||||
|
||||
@@ -484,7 +484,7 @@ impl<'a> WindowContext<'a> {
|
||||
/// use within your future.
|
||||
pub fn spawn<Fut, R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(AnyWindowHandle, AsyncWindowContext) -> Fut + Send + 'static,
|
||||
f: impl FnOnce(AnyWindowHandle, AsyncWindowContext) -> Fut,
|
||||
) -> Task<R>
|
||||
where
|
||||
R: Send + 'static,
|
||||
@@ -493,8 +493,7 @@ impl<'a> WindowContext<'a> {
|
||||
let window = self.window.handle;
|
||||
self.app.spawn(move |app| {
|
||||
let cx = AsyncWindowContext::new(app, window);
|
||||
let future = f(window, cx);
|
||||
async move { future.await }
|
||||
f(window, cx)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1872,17 +1871,14 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||
|
||||
pub fn spawn<Fut, R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(WeakView<V>, AsyncWindowContext) -> Fut + Send + 'static,
|
||||
f: impl FnOnce(WeakView<V>, AsyncWindowContext) -> Fut,
|
||||
) -> Task<R>
|
||||
where
|
||||
R: Send + 'static,
|
||||
Fut: Future<Output = R> + Send + 'static,
|
||||
{
|
||||
let view = self.view().downgrade();
|
||||
self.window_cx.spawn(move |_, cx| {
|
||||
let result = f(view, cx);
|
||||
async move { result.await }
|
||||
})
|
||||
self.window_cx.spawn(move |_, cx| f(view, cx))
|
||||
}
|
||||
|
||||
pub fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
|
||||
|
||||
Reference in New Issue
Block a user