diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs index d931488145..2e01f664b4 100644 --- a/crates/gpui2/src/app/model_context.rs +++ b/crates/gpui2/src/app/model_context.rs @@ -1,8 +1,8 @@ use crate::{ - AppContext, Context, Effect, EntityId, EventEmitter, Executor, Handle, Reference, Subscription, - WeakHandle, + AppContext, AsyncAppContext, Context, Effect, EntityId, EventEmitter, Handle, Reference, + Subscription, Task, WeakHandle, }; -use std::marker::PhantomData; +use std::{future::Future, marker::PhantomData}; pub struct ModelContext<'a, T> { app: Reference<'a, AppContext>, @@ -112,6 +112,18 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> { self.app.push_global(global); result } + + pub fn spawn( + &self, + f: impl FnOnce(WeakHandle, AsyncAppContext) -> Fut + Send + 'static, + ) -> Task + where + Fut: Future + Send + 'static, + R: Send + 'static, + { + let this = self.handle(); + self.app.spawn(|cx| f(this, cx)) + } } impl<'a, T: EventEmitter + Send + Sync + 'static> ModelContext<'a, T> {