diff options
Diffstat (limited to 'crates/ra_analysis/src/job.rs')
-rw-r--r-- | crates/ra_analysis/src/job.rs | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/crates/ra_analysis/src/job.rs b/crates/ra_analysis/src/job.rs deleted file mode 100644 index 2871f9839..000000000 --- a/crates/ra_analysis/src/job.rs +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | use crossbeam_channel::{bounded, Receiver, Sender}; | ||
2 | |||
3 | pub struct JobHandle { | ||
4 | job_alive: Receiver<Never>, | ||
5 | _job_canceled: Sender<Never>, | ||
6 | } | ||
7 | |||
8 | pub struct JobToken { | ||
9 | _job_alive: Sender<Never>, | ||
10 | job_canceled: Receiver<Never>, | ||
11 | } | ||
12 | |||
13 | impl JobHandle { | ||
14 | pub fn new() -> (JobHandle, JobToken) { | ||
15 | let (sender_alive, receiver_alive) = bounded(0); | ||
16 | let (sender_canceled, receiver_canceled) = bounded(0); | ||
17 | let token = JobToken { | ||
18 | _job_alive: sender_alive, | ||
19 | job_canceled: receiver_canceled, | ||
20 | }; | ||
21 | let handle = JobHandle { | ||
22 | job_alive: receiver_alive, | ||
23 | _job_canceled: sender_canceled, | ||
24 | }; | ||
25 | (handle, token) | ||
26 | } | ||
27 | pub fn has_completed(&self) -> bool { | ||
28 | is_closed(&self.job_alive) | ||
29 | } | ||
30 | pub fn cancel(self) {} | ||
31 | } | ||
32 | |||
33 | impl JobToken { | ||
34 | pub fn is_canceled(&self) -> bool { | ||
35 | is_closed(&self.job_canceled) | ||
36 | } | ||
37 | } | ||
38 | |||
39 | // We don't actually send messages through the channels, | ||
40 | // and instead just check if the channel is closed, | ||
41 | // so we use uninhabited enum as a message type | ||
42 | enum Never {} | ||
43 | |||
44 | /// Nonblocking | ||
45 | fn is_closed(chan: &Receiver<Never>) -> bool { | ||
46 | select! { | ||
47 | recv(chan, msg) => match msg { | ||
48 | None => true, | ||
49 | Some(never) => match never {} | ||
50 | } | ||
51 | default => false, | ||
52 | } | ||
53 | } | ||