simplify frontend layer
remove the executor bits that now reside in promise::spawn
This commit is contained in:
1 parent
b295575953
commit
efd1db8581
3 files changed
+2
-82
No files matched your search
@@ -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<dyn Executor> {
|
||||
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<dyn Executor> {
|
||||
Box::new(Self {})
|
||||
}
|
||||
}
|
||||
|
||||
impl FrontEnd for GuiFrontEnd {
|
||||
fn executor(&self) -> Box<dyn Executor> {
|
||||
Box::new(GuiExecutor {})
|
||||
}
|
||||
|
||||
fn low_pri_executor(&self) -> Box<dyn Executor> {
|
||||
Box::new(GuiExecutor {})
|
||||
}
|
||||
|
||||
fn run_forever(&self) -> anyhow::Result<()> {
|
||||
self.connection
|
||||
.schedule_timer(std::time::Duration::from_millis(200), move || {
|
||||
|
||||
@@ -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<Option<Box<dyn Executor>>> = Mutex::new(None);
|
||||
static ref LOW_PRI_EXECUTOR: Mutex<Option<Box<dyn Executor>>> = Mutex::new(None);
|
||||
}
|
||||
thread_local! {
|
||||
static FRONT_END: RefCell<Option<Rc<dyn FrontEnd>>> = 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<dyn Tab>,
|
||||
window_id: WindowId,
|
||||
) -> anyhow::Result<()>;
|
||||
|
||||
fn executor(&self) -> Box<dyn Executor>;
|
||||
fn low_pri_executor(&self) -> Box<dyn Executor>;
|
||||
}
|
||||
impl_downcast!(FrontEnd);
|
||||
@@ -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<SpawnFunc>,
|
||||
}
|
||||
|
||||
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<dyn Executor> {
|
||||
Box::new(MuxExecutor {
|
||||
tx: self.tx.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MuxServerFrontEnd {
|
||||
tx: Sender<SpawnFunc>,
|
||||
rx: Receiver<SpawnFunc>,
|
||||
}
|
||||
|
||||
@@ -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<Rc<dyn FrontEnd>, Error> {
|
||||
@@ -69,16 +49,6 @@ impl MuxServerFrontEnd {
|
||||
}
|
||||
|
||||
impl FrontEnd for MuxServerFrontEnd {
|
||||
fn executor(&self) -> Box<dyn Executor> {
|
||||
Box::new(MuxExecutor {
|
||||
tx: self.tx.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
fn low_pri_executor(&self) -> Box<dyn Executor> {
|
||||
self.executor()
|
||||
}
|
||||
|
||||
fn run_forever(&self) -> Result<(), Error> {
|
||||
loop {
|
||||
match self.rx.recv() {
|
||||
|
||||
Reference in new issue
Block a user