mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Fix shutdown behavoir of main cargo-watch thread.
Even though this didn't error, it became clear to me that it was closing the wrong channel, resulting in the child thread never finishing.
This commit is contained in:
parent
59837c75f4
commit
ed84c85aef
1 changed files with 8 additions and 7 deletions
|
@ -36,7 +36,7 @@ pub struct CheckOptions {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CheckWatcher {
|
pub struct CheckWatcher {
|
||||||
pub task_recv: Receiver<CheckTask>,
|
pub task_recv: Receiver<CheckTask>,
|
||||||
pub cmd_send: Sender<CheckCommand>,
|
pub cmd_send: Option<Sender<CheckCommand>>,
|
||||||
pub shared: Arc<RwLock<CheckWatcherSharedState>>,
|
pub shared: Arc<RwLock<CheckWatcherSharedState>>,
|
||||||
handle: Option<JoinHandle<()>>,
|
handle: Option<JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
@ -53,23 +53,24 @@ impl CheckWatcher {
|
||||||
let mut check = CheckWatcherState::new(options, workspace_root, shared_);
|
let mut check = CheckWatcherState::new(options, workspace_root, shared_);
|
||||||
check.run(&task_send, &cmd_recv);
|
check.run(&task_send, &cmd_recv);
|
||||||
});
|
});
|
||||||
CheckWatcher { task_recv, cmd_send, handle: Some(handle), shared }
|
CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle), shared }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Schedule a re-start of the cargo check worker.
|
/// Schedule a re-start of the cargo check worker.
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
self.cmd_send.send(CheckCommand::Update).unwrap();
|
if let Some(cmd_send) = &self.cmd_send {
|
||||||
|
cmd_send.send(CheckCommand::Update).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Drop for CheckWatcher {
|
impl std::ops::Drop for CheckWatcher {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
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
|
// Take the sender out of the option
|
||||||
// one actually communicating with the thread
|
let recv = self.cmd_send.take();
|
||||||
let recv = std::mem::replace(&mut self.task_recv, crossbeam_channel::never());
|
|
||||||
|
|
||||||
// Dropping the original reciever finishes the thread loop
|
// Dropping the sender finishes the thread loop
|
||||||
drop(recv);
|
drop(recv);
|
||||||
|
|
||||||
// Join the thread, it should finish shortly. We don't really care
|
// Join the thread, it should finish shortly. We don't really care
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue