aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_cargo_watch/src/lib.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs
index d17edd775..11b624abf 100644
--- a/crates/ra_cargo_watch/src/lib.rs
+++ b/crates/ra_cargo_watch/src/lib.rs
@@ -36,7 +36,7 @@ pub struct CheckOptions {
36#[derive(Debug)] 36#[derive(Debug)]
37pub struct CheckWatcher { 37pub struct CheckWatcher {
38 pub task_recv: Receiver<CheckTask>, 38 pub task_recv: Receiver<CheckTask>,
39 pub cmd_send: Sender<CheckCommand>, 39 pub cmd_send: Option<Sender<CheckCommand>>,
40 pub shared: Arc<RwLock<CheckWatcherSharedState>>, 40 pub shared: Arc<RwLock<CheckWatcherSharedState>>,
41 handle: Option<JoinHandle<()>>, 41 handle: Option<JoinHandle<()>>,
42} 42}
@@ -53,23 +53,24 @@ impl CheckWatcher {
53 let mut check = CheckWatcherState::new(options, workspace_root, shared_); 53 let mut check = CheckWatcherState::new(options, workspace_root, shared_);
54 check.run(&task_send, &cmd_recv); 54 check.run(&task_send, &cmd_recv);
55 }); 55 });
56 CheckWatcher { task_recv, cmd_send, handle: Some(handle), shared } 56 CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle), shared }
57 } 57 }
58 58
59 /// Schedule a re-start of the cargo check worker. 59 /// Schedule a re-start of the cargo check worker.
60 pub fn update(&self) { 60 pub fn update(&self) {
61 self.cmd_send.send(CheckCommand::Update).unwrap(); 61 if let Some(cmd_send) = &self.cmd_send {
62 cmd_send.send(CheckCommand::Update).unwrap();
63 }
62 } 64 }
63} 65}
64 66
65impl std::ops::Drop for CheckWatcher { 67impl std::ops::Drop for CheckWatcher {
66 fn drop(&mut self) { 68 fn drop(&mut self) {
67 if let Some(handle) = self.handle.take() { 69 if let Some(handle) = self.handle.take() {
68 // Replace our reciever with dummy one, so we can drop and close the 70 // Take the sender out of the option
69 // one actually communicating with the thread 71 let recv = self.cmd_send.take();
70 let recv = std::mem::replace(&mut self.task_recv, crossbeam_channel::never());
71 72
72 // Dropping the original reciever finishes the thread loop 73 // Dropping the sender finishes the thread loop
73 drop(recv); 74 drop(recv);
74 75
75 // Join the thread, it should finish shortly. We don't really care 76 // Join the thread, it should finish shortly. We don't really care