From 379a096de9ad06c23347b76a54d9cc22aee80f6a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 25 Jun 2020 17:14:11 +0200 Subject: Refactor main_loop --- crates/flycheck/src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'crates/flycheck/src') diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 9e8205ae7..4dcab7a61 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -120,7 +120,13 @@ impl FlycheckActor { ) -> FlycheckActor { FlycheckActor { sender, config, workspace_root, last_update_req: None, check_process: None } } - + fn next_event(&self, inbox: &Receiver) -> Option { + let check_chan = self.check_process.as_ref().map(|(chan, _thread)| chan); + select! { + recv(inbox) -> msg => msg.ok().map(Event::Restart), + recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())), + } + } fn run(&mut self, inbox: Receiver) { // If we rerun the thread, we need to discard the previous check results first self.send(Message::ClearDiagnostics); @@ -167,15 +173,6 @@ impl FlycheckActor { } } } - - fn next_event(&self, inbox: &Receiver) -> Option { - let check_chan = self.check_process.as_ref().map(|(chan, _thread)| chan); - select! { - recv(inbox) -> msg => msg.ok().map(Event::Restart), - recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())), - } - } - fn should_recheck(&mut self) -> bool { if let Some(_last_update_req) = &self.last_update_req { // We currently only request an update on save, as we need up to -- cgit v1.2.3