WIP

Antonio Scandurra created

Change summary

crates/gpui3/src/app.rs    | 12 ++++++++++++
crates/gpui3/src/window.rs | 28 +++++++++++++++++++++-------
2 files changed, 33 insertions(+), 7 deletions(-)

Detailed changes

crates/gpui3/src/app.rs 🔗

@@ -225,6 +225,18 @@ impl AppContext {
         })
     }
 
+    pub fn spawn<Fut, R>(&self, f: impl FnOnce(&mut AppContext) -> Fut + Send + 'static) -> Task<R>
+    where
+        Fut: Future<Output = R> + Send + 'static,
+        R: Send + 'static,
+    {
+        let this = self.this.upgrade().unwrap();
+        self.executor.spawn(async move {
+            let future = f(&mut this.lock());
+            future.await
+        })
+    }
+
     pub fn text_system(&self) -> &Arc<TextSystem> {
         &self.text_system
     }

crates/gpui3/src/window.rs 🔗

@@ -1,14 +1,14 @@
 use crate::{
-    image_cache::RenderImageParams, px, AnyView, AppContext, AvailableSpace, BorrowAppContext,
-    Bounds, Context, Corners, DevicePixels, Effect, Element, EntityId, FontId, GlyphId, Handle,
-    Hsla, ImageData, IsZero, LayerId, LayoutId, MainThread, MainThreadOnly, MonochromeSprite,
-    Pixels, PlatformAtlas, PlatformWindow, Point, PolychromeSprite, Reference, RenderGlyphParams,
-    RenderSvgParams, ScaledPixels, Scene, SharedString, Size, Style, TaffyLayoutEngine, Task,
-    WeakHandle, WindowOptions, SUBPIXEL_VARIANTS,
+    image_cache::RenderImageParams, px, AnyView, AppContext, AsyncContext, AvailableSpace,
+    BorrowAppContext, Bounds, Context, Corners, DevicePixels, Effect, Element, EntityId, FontId,
+    GlyphId, Handle, Hsla, ImageData, IsZero, LayerId, LayoutId, MainThread, MainThreadOnly,
+    MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, PolychromeSprite, Reference,
+    RenderGlyphParams, RenderSvgParams, ScaledPixels, Scene, SharedString, Size, Style,
+    TaffyLayoutEngine, Task, WeakHandle, WindowOptions, SUBPIXEL_VARIANTS,
 };
 use anyhow::Result;
 use smallvec::SmallVec;
-use std::{any::TypeId, borrow::Cow, marker::PhantomData, mem, sync::Arc};
+use std::{any::TypeId, borrow::Cow, future::Future, marker::PhantomData, mem, sync::Arc};
 use util::ResultExt;
 
 pub struct AnyWindow {}
@@ -601,6 +601,20 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
         }
     }
 
+    pub fn spawn<Fut, R>(
+        &mut self,
+        f: impl FnOnce(&mut S, &mut ViewContext<'_, '_, S>) -> Fut + Send + 'static,
+    ) -> Task<Result<R>>
+    where
+        Fut: Future<Output = R> + Send + 'static,
+    {
+        let handle = self.handle();
+        todo!()
+        // self.window_cx.spawn(|cx| {
+        //     f
+        // })
+    }
+
     pub(crate) fn erase_state<R>(&mut self, f: impl FnOnce(&mut ViewContext<()>) -> R) -> R {
         let entity_id = self.unit_entity.id;
         let mut cx = ViewContext::mutable(