diff options
author | Emil Lauridsen <[email protected]> | 2019-12-27 11:42:18 +0000 |
---|---|---|
committer | Emil Lauridsen <[email protected]> | 2019-12-27 11:42:18 +0000 |
commit | ed84c85aef859e97ab355e78bf77f435689f25b7 (patch) | |
tree | 43fb1ad30dfc2bcf9cbe87908670813530111708 /crates | |
parent | 59837c75f44f4b1b6a09e8db7e59a7bbd78d074a (diff) |
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.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_cargo_watch/src/lib.rs | 15 |
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)] |
37 | pub struct CheckWatcher { | 37 | pub 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 | ||
65 | impl std::ops::Drop for CheckWatcher { | 67 | impl 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 |