Make background executor available on AppContext
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
fabc19402a
commit
c39c7c3eff
1 changed files with 14 additions and 6 deletions
|
@ -311,7 +311,6 @@ pub struct MutableAppContext {
|
||||||
invalidation_callbacks:
|
invalidation_callbacks:
|
||||||
HashMap<usize, Box<dyn FnMut(WindowInvalidation, &mut MutableAppContext)>>,
|
HashMap<usize, Box<dyn FnMut(WindowInvalidation, &mut MutableAppContext)>>,
|
||||||
foreground: Rc<executor::Foreground>,
|
foreground: Rc<executor::Foreground>,
|
||||||
background: Arc<executor::Background>,
|
|
||||||
future_handlers: Rc<RefCell<HashMap<usize, FutureHandler>>>,
|
future_handlers: Rc<RefCell<HashMap<usize, FutureHandler>>>,
|
||||||
stream_handlers: Rc<RefCell<HashMap<usize, StreamHandler>>>,
|
stream_handlers: Rc<RefCell<HashMap<usize, StreamHandler>>>,
|
||||||
task_done: Arc<Condvar>,
|
task_done: Arc<Condvar>,
|
||||||
|
@ -336,6 +335,7 @@ impl MutableAppContext {
|
||||||
models: HashMap::new(),
|
models: HashMap::new(),
|
||||||
windows: HashMap::new(),
|
windows: HashMap::new(),
|
||||||
ref_counts: Arc::new(Mutex::new(RefCounts::default())),
|
ref_counts: Arc::new(Mutex::new(RefCounts::default())),
|
||||||
|
background: Arc::new(executor::Background::new()),
|
||||||
},
|
},
|
||||||
actions: HashMap::new(),
|
actions: HashMap::new(),
|
||||||
global_actions: HashMap::new(),
|
global_actions: HashMap::new(),
|
||||||
|
@ -348,7 +348,6 @@ impl MutableAppContext {
|
||||||
window_invalidations: HashMap::new(),
|
window_invalidations: HashMap::new(),
|
||||||
invalidation_callbacks: HashMap::new(),
|
invalidation_callbacks: HashMap::new(),
|
||||||
foreground,
|
foreground,
|
||||||
background: Arc::new(executor::Background::new()),
|
|
||||||
future_handlers: Default::default(),
|
future_handlers: Default::default(),
|
||||||
stream_handlers: Default::default(),
|
stream_handlers: Default::default(),
|
||||||
task_done: Default::default(),
|
task_done: Default::default(),
|
||||||
|
@ -366,8 +365,12 @@ impl MutableAppContext {
|
||||||
&self.ctx
|
&self.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn foreground_executor(&self) -> Rc<executor::Foreground> {
|
pub fn foreground_executor(&self) -> &Rc<executor::Foreground> {
|
||||||
self.foreground.clone()
|
&self.foreground
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||||
|
&self.ctx.background
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_window_invalidated<F: 'static + FnMut(WindowInvalidation, &mut MutableAppContext)>(
|
pub fn on_window_invalidated<F: 'static + FnMut(WindowInvalidation, &mut MutableAppContext)>(
|
||||||
|
@ -1294,6 +1297,7 @@ impl UpdateView for MutableAppContext {
|
||||||
pub struct AppContext {
|
pub struct AppContext {
|
||||||
models: HashMap<usize, Box<dyn AnyModel>>,
|
models: HashMap<usize, Box<dyn AnyModel>>,
|
||||||
windows: HashMap<usize, Window>,
|
windows: HashMap<usize, Window>,
|
||||||
|
background: Arc<executor::Background>,
|
||||||
ref_counts: Arc<Mutex<RefCounts>>,
|
ref_counts: Arc<Mutex<RefCounts>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1329,6 +1333,10 @@ impl AppContext {
|
||||||
})
|
})
|
||||||
.ok_or(anyhow!("window not found"))
|
.ok_or(anyhow!("window not found"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||||
|
&self.background
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModelAsRef for AppContext {
|
impl ModelAsRef for AppContext {
|
||||||
|
@ -1480,7 +1488,7 @@ impl<'a, T: Entity> ModelContext<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||||
&self.app.background
|
&self.app.ctx.background
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn halt_stream(&mut self) {
|
pub fn halt_stream(&mut self) {
|
||||||
|
@ -1673,7 +1681,7 @@ impl<'a, T: View> ViewContext<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||||
&self.app.background
|
&self.app.ctx.background
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus<S>(&mut self, handle: S)
|
pub fn focus<S>(&mut self, handle: S)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue