aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cargo_watch/src
diff options
context:
space:
mode:
authorEmil Lauridsen <[email protected]>2019-12-27 16:29:02 +0000
committerEmil Lauridsen <[email protected]>2019-12-27 16:29:02 +0000
commit899dbebd02b41b12d89c9f485e85208b39b81932 (patch)
tree19032c518e0bbfa6de13bb91ba4ecb56e349e717 /crates/ra_cargo_watch/src
parentc732f215cb31e9f022090b8d0212f6ea9c134c11 (diff)
Fix busy-waiting issue in main cargo watch thread
Diffstat (limited to 'crates/ra_cargo_watch/src')
-rw-r--r--crates/ra_cargo_watch/src/lib.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs
index d683d43d2..78250f910 100644
--- a/crates/ra_cargo_watch/src/lib.rs
+++ b/crates/ra_cargo_watch/src/lib.rs
@@ -2,7 +2,7 @@
2//! another compatible command (f.x. clippy) in a background thread and provide 2//! another compatible command (f.x. clippy) in a background thread and provide
3//! LSP diagnostics based on the output of the command. 3//! LSP diagnostics based on the output of the command.
4use cargo_metadata::Message; 4use cargo_metadata::Message;
5use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; 5use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender};
6use lsp_types::{ 6use lsp_types::{
7 Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd, 7 Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd,
8 WorkDoneProgressReport, 8 WorkDoneProgressReport,
@@ -193,7 +193,9 @@ impl CheckWatcherState {
193 recv(self.watcher.message_recv) -> msg => match msg { 193 recv(self.watcher.message_recv) -> msg => match msg {
194 Ok(msg) => self.handle_message(msg, task_send), 194 Ok(msg) => self.handle_message(msg, task_send),
195 Err(RecvError) => { 195 Err(RecvError) => {
196 // Watcher finished, do nothing. 196 // Watcher finished, replace it with a never channel to
197 // avoid busy-waiting.
198 std::mem::replace(&mut self.watcher.message_recv, never());
197 }, 199 },
198 } 200 }
199 }; 201 };
@@ -370,7 +372,7 @@ impl std::ops::Drop for WatchThread {
370 if let Some(handle) = self.handle.take() { 372 if let Some(handle) = self.handle.take() {
371 // Replace our reciever with dummy one, so we can drop and close the 373 // Replace our reciever with dummy one, so we can drop and close the
372 // one actually communicating with the thread 374 // one actually communicating with the thread
373 let recv = std::mem::replace(&mut self.message_recv, crossbeam_channel::never()); 375 let recv = std::mem::replace(&mut self.message_recv, never());
374 376
375 // Dropping the original reciever initiates thread sub-process shutdown 377 // Dropping the original reciever initiates thread sub-process shutdown
376 drop(recv); 378 drop(recv);