Make the gpui_tokio crate generic over the context it spawns (#23995)

Part of  #21092

Makes `Tokio::spawn` generic over any `AppContext`.

Also removes a stray `model_context` I missed

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-01-30 18:00:55 -08:00 committed by GitHub
parent ff43b6875b
commit 517e519bdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 133 additions and 18 deletions

View file

@ -104,6 +104,22 @@ impl AppContext for AsyncApp {
let lock = app.borrow();
lock.read_window(window, read)
}
fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
where
R: Send + 'static,
{
self.background_executor.spawn(future)
}
fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> Self::Result<R>
where
G: Global,
{
let app = self.app.upgrade().context("app was released")?;
let mut lock = app.borrow_mut();
Ok(lock.update(|this| this.read_global(callback)))
}
}
impl AsyncApp {
@ -367,6 +383,20 @@ impl AppContext for AsyncWindowContext {
{
self.app.read_window(window, read)
}
fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
where
R: Send + 'static,
{
self.app.background_executor.spawn(future)
}
fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> Result<R>
where
G: Global,
{
self.app.read_global(callback)
}
}
impl VisualContext for AsyncWindowContext {