mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Fix busy-waiting issue in main cargo watch thread
This commit is contained in:
parent
c732f215cb
commit
899dbebd02
1 changed files with 5 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
||||||
//! another compatible command (f.x. clippy) in a background thread and provide
|
//! another compatible command (f.x. clippy) in a background thread and provide
|
||||||
//! LSP diagnostics based on the output of the command.
|
//! LSP diagnostics based on the output of the command.
|
||||||
use cargo_metadata::Message;
|
use cargo_metadata::Message;
|
||||||
use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender};
|
use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender};
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd,
|
Diagnostic, Url, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd,
|
||||||
WorkDoneProgressReport,
|
WorkDoneProgressReport,
|
||||||
|
@ -193,7 +193,9 @@ impl CheckWatcherState {
|
||||||
recv(self.watcher.message_recv) -> msg => match msg {
|
recv(self.watcher.message_recv) -> msg => match msg {
|
||||||
Ok(msg) => self.handle_message(msg, task_send),
|
Ok(msg) => self.handle_message(msg, task_send),
|
||||||
Err(RecvError) => {
|
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 @@ impl std::ops::Drop for WatchThread {
|
||||||
if let Some(handle) = self.handle.take() {
|
if let Some(handle) = self.handle.take() {
|
||||||
// Replace our reciever with dummy one, so we can drop and close the
|
// Replace our reciever with dummy one, so we can drop and close the
|
||||||
// one actually communicating with the thread
|
// 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
|
// Dropping the original reciever initiates thread sub-process shutdown
|
||||||
drop(recv);
|
drop(recv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue