Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

WIP

Antonio Scandurra7171818d24ba
diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs
index d9314881455..2e01f664b4f 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<Fut, R>(
+ &self,
+ f: impl FnOnce(WeakHandle<T>, AsyncAppContext) -> Fut + Send + 'static,
+ ) -> Task<R>
+ where
+ Fut: Future<Output = R> + 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> {