From 941d4bfa53ebf4dd683889c2151544bcc3095073 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 25 Jun 2020 09:26:13 +0200 Subject: Simplify --- crates/flycheck/src/lib.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'crates/flycheck/src/lib.rs') diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 0f23e97f7..3e73cf6ff 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -49,7 +49,7 @@ impl fmt::Display for FlycheckConfig { #[derive(Debug)] pub struct FlycheckHandle { // XXX: drop order is significant - cmd_send: Sender, + cmd_send: Sender, handle: jod_thread::JoinHandle, } @@ -59,7 +59,7 @@ impl FlycheckHandle { config: FlycheckConfig, workspace_root: PathBuf, ) -> FlycheckHandle { - let (cmd_send, cmd_recv) = unbounded::(); + let (cmd_send, cmd_recv) = unbounded::(); let handle = jod_thread::spawn(move || { FlycheckActor::new(sender, config, workspace_root).run(&cmd_recv); }); @@ -68,7 +68,7 @@ impl FlycheckHandle { /// Schedule a re-start of the cargo check worker. pub fn update(&self) { - self.cmd_send.send(CheckCommand::Update).unwrap(); + self.cmd_send.send(Restart).unwrap(); } } @@ -91,10 +91,7 @@ pub enum Progress { End, } -enum CheckCommand { - /// Request re-start of check thread - Update, -} +struct Restart; struct FlycheckActor { sender: Box, @@ -127,14 +124,14 @@ impl FlycheckActor { } } - fn run(&mut self, cmd_recv: &Receiver) { + fn run(&mut self, cmd_recv: &Receiver) { // If we rerun the thread, we need to discard the previous check results first self.clean_previous_results(); loop { select! { recv(&cmd_recv) -> cmd => match cmd { - Ok(cmd) => self.handle_command(cmd), + Ok(Restart) => self.last_update_req = Some(Instant::now()), Err(RecvError) => { // Command channel has closed, so shut down break; @@ -174,12 +171,6 @@ impl FlycheckActor { false } - fn handle_command(&mut self, cmd: CheckCommand) { - match cmd { - CheckCommand::Update => self.last_update_req = Some(Instant::now()), - } - } - fn handle_message(&self, msg: CheckEvent) { match msg { CheckEvent::Begin => { -- cgit v1.2.3