From 899dbebd02b41b12d89c9f485e85208b39b81932 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Fri, 27 Dec 2019 17:29:02 +0100 Subject: [PATCH] Fix busy-waiting issue in main cargo watch thread --- crates/ra_cargo_watch/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs index d683d43d20a..78250f91075 100644 --- a/crates/ra_cargo_watch/src/lib.rs +++ b/crates/ra_cargo_watch/src/lib.rs @@ -2,7 +2,7 @@ //! another compatible command (f.x. clippy) in a background thread and provide //! LSP diagnostics based on the output of the command. use cargo_metadata::Message; -use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; +use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender}; use lsp_types::{ Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd, WorkDoneProgressReport, @@ -193,7 +193,9 @@ pub fn run(&mut self, task_send: &Sender, cmd_recv: &Receiver msg => match msg { Ok(msg) => self.handle_message(msg, task_send), Err(RecvError) => { - // Watcher finished, do nothing. + // Watcher finished, replace it with a never channel to + // avoid busy-waiting. + std::mem::replace(&mut self.watcher.message_recv, never()); }, } }; @@ -370,7 +372,7 @@ fn drop(&mut self) { if let Some(handle) = self.handle.take() { // Replace our reciever with dummy one, so we can drop and close the // one actually communicating with the thread - let recv = std::mem::replace(&mut self.message_recv, crossbeam_channel::never()); + let recv = std::mem::replace(&mut self.message_recv, never()); // Dropping the original reciever initiates thread sub-process shutdown drop(recv); -- 2.44.0