From efd1db8581fcf78da28f03f6d516f611a059d294 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 16 Jan 2020 23:17:01 -0800 Subject: [PATCH] simplify frontend layer remove the executor bits that now reside in promise::spawn --- src/frontend/gui/mod.rs | 35 ----------------------------------- src/frontend/mod.rs | 15 --------------- src/frontend/muxserver/mod.rs | 34 ++-------------------------------- 3 files changed, 2 insertions(+), 82 deletions(-) diff --git a/src/frontend/gui/mod.rs b/src/frontend/gui/mod.rs index 5f694b351..e4c9be556 100644 --- a/src/frontend/gui/mod.rs +++ b/src/frontend/gui/mod.rs @@ -5,7 +5,6 @@ use crate::mux::tab::Tab; use crate::mux::window::WindowId as MuxWindowId; use crate::mux::Mux; use ::window::*; -use promise::{BasicExecutor, Executor, SpawnFunc}; use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; @@ -47,41 +46,7 @@ impl GuiFrontEnd { } } -struct GuiExecutor {} -impl BasicExecutor for GuiExecutor { - fn execute(&self, f: SpawnFunc) { - Connection::executor().execute(f) - } -} - -impl Executor for GuiExecutor { - fn clone_executor(&self) -> Box { - Box::new(GuiExecutor {}) - } -} - -struct LowPriGuiExecutor {} -impl BasicExecutor for LowPriGuiExecutor { - fn execute(&self, f: SpawnFunc) { - Connection::low_pri_executor().execute(f) - } -} - -impl Executor for LowPriGuiExecutor { - fn clone_executor(&self) -> Box { - Box::new(Self {}) - } -} - impl FrontEnd for GuiFrontEnd { - fn executor(&self) -> Box { - Box::new(GuiExecutor {}) - } - - fn low_pri_executor(&self) -> Box { - Box::new(GuiExecutor {}) - } - fn run_forever(&self) -> anyhow::Result<()> { self.connection .schedule_timer(std::time::Duration::from_millis(200), move || { diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index 478c8e775..7e306d2e0 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -3,12 +3,9 @@ use crate::mux::tab::Tab; use crate::mux::window::WindowId; use anyhow::{anyhow, Error}; use downcast_rs::{impl_downcast, Downcast}; -use lazy_static::lazy_static; -use promise::Executor; use serde::Deserialize; use std::cell::RefCell; use std::rc::Rc; -use std::sync::Mutex; pub mod activity; pub mod gui; @@ -28,10 +25,6 @@ impl Default for FrontEndSelection { } } -lazy_static! { - static ref EXECUTOR: Mutex>> = Mutex::new(None); - static ref LOW_PRI_EXECUTOR: Mutex>> = Mutex::new(None); -} thread_local! { static FRONT_END: RefCell>> = RefCell::new(None); } @@ -55,11 +48,6 @@ impl FrontEndSelection { FrontEndSelection::OpenGL => gui::GuiFrontEnd::try_new(), }?; - EXECUTOR.lock().unwrap().replace(front_end.executor()); - LOW_PRI_EXECUTOR - .lock() - .unwrap() - .replace(front_end.low_pri_executor()); FRONT_END.with(|f| *f.borrow_mut() = Some(Rc::clone(&front_end))); Ok(front_end) @@ -99,8 +87,5 @@ pub trait FrontEnd: Downcast { tab: &Rc, window_id: WindowId, ) -> anyhow::Result<()>; - - fn executor(&self) -> Box; - fn low_pri_executor(&self) -> Box; } impl_downcast!(FrontEnd); diff --git a/src/frontend/muxserver/mod.rs b/src/frontend/muxserver/mod.rs index 3f2059b67..22ef8e508 100644 --- a/src/frontend/muxserver/mod.rs +++ b/src/frontend/muxserver/mod.rs @@ -6,32 +6,12 @@ use crate::mux::window::WindowId; use crate::mux::Mux; use crate::server::listener::spawn_listener; use anyhow::{bail, Error}; -use crossbeam_channel::{unbounded as channel, Receiver, Sender}; +use crossbeam_channel::{unbounded as channel, Receiver}; use log::info; use promise::*; use std::rc::Rc; -#[derive(Clone)] -struct MuxExecutor { - tx: Sender, -} - -impl BasicExecutor for MuxExecutor { - fn execute(&self, f: SpawnFunc) { - self.tx.send(f).expect("MuxExecutor execute failed"); - } -} - -impl Executor for MuxExecutor { - fn clone_executor(&self) -> Box { - Box::new(MuxExecutor { - tx: self.tx.clone(), - }) - } -} - pub struct MuxServerFrontEnd { - tx: Sender, rx: Receiver, } @@ -56,7 +36,7 @@ impl MuxServerFrontEnd { if start_listener { spawn_listener()?; } - Ok(Rc::new(Self { tx, rx })) + Ok(Rc::new(Self { rx })) } pub fn try_new() -> Result, Error> { @@ -69,16 +49,6 @@ impl MuxServerFrontEnd { } impl FrontEnd for MuxServerFrontEnd { - fn executor(&self) -> Box { - Box::new(MuxExecutor { - tx: self.tx.clone(), - }) - } - - fn low_pri_executor(&self) -> Box { - self.executor() - } - fn run_forever(&self) -> Result<(), Error> { loop { match self.rx.recv() {