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:
parent
ff43b6875b
commit
517e519bdc
7 changed files with 133 additions and 18 deletions
|
@ -22,9 +22,9 @@ use slotmap::SlotMap;
|
|||
|
||||
pub use async_context::*;
|
||||
use collections::{FxHashMap, FxHashSet, HashMap, VecDeque};
|
||||
pub use context::*;
|
||||
pub use entity_map::*;
|
||||
use http_client::HttpClient;
|
||||
pub use model_context::*;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub use test_context::*;
|
||||
use util::ResultExt;
|
||||
|
@ -41,8 +41,8 @@ use crate::{
|
|||
};
|
||||
|
||||
mod async_context;
|
||||
mod context;
|
||||
mod entity_map;
|
||||
mod model_context;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
mod test_context;
|
||||
|
||||
|
@ -1667,6 +1667,21 @@ impl AppContext for App {
|
|||
|
||||
Ok(read(view, self))
|
||||
}
|
||||
|
||||
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 mut g = self.global::<G>();
|
||||
callback(&g, self)
|
||||
}
|
||||
}
|
||||
|
||||
/// These effects are processed at the end of each application update cycle.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue