aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-31 08:27:38 +0100
committerAleksey Kladov <[email protected]>2018-08-31 08:27:38 +0100
commitefa6a952b4cb9c9f139822fbf9781a610bba3813 (patch)
treed631880d0109a691505f03898959490c8db596de /crates/libanalysis
parent902df0fc054eb962987a850ba1b32bed59b59623 (diff)
cancelation tokens
Diffstat (limited to 'crates/libanalysis')
-rw-r--r--crates/libanalysis/Cargo.toml1
-rw-r--r--crates/libanalysis/src/job.rs49
-rw-r--r--crates/libanalysis/src/lib.rs4
3 files changed, 54 insertions, 0 deletions
diff --git a/crates/libanalysis/Cargo.toml b/crates/libanalysis/Cargo.toml
index 1f072533c..9c7977e92 100644
--- a/crates/libanalysis/Cargo.toml
+++ b/crates/libanalysis/Cargo.toml
@@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"]
6[dependencies] 6[dependencies]
7relative-path = "0.3.7" 7relative-path = "0.3.7"
8log = "0.4.2" 8log = "0.4.2"
9crossbeam-channel = "0.2.4"
9parking_lot = "0.6.3" 10parking_lot = "0.6.3"
10once_cell = "0.1.4" 11once_cell = "0.1.4"
11rayon = "1.0.2" 12rayon = "1.0.2"
diff --git a/crates/libanalysis/src/job.rs b/crates/libanalysis/src/job.rs
new file mode 100644
index 000000000..4d393b915
--- /dev/null
+++ b/crates/libanalysis/src/job.rs
@@ -0,0 +1,49 @@
1use crossbeam_channel::{bounded, Receiver, Sender};
2
3pub struct JobHandle {
4 job_alive: Receiver<Never>,
5 _job_canceled: Sender<Never>,
6}
7
8pub struct JobToken {
9 _job_alive: Sender<Never>,
10 job_canceled: Receiver<Never>,
11}
12
13impl 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 { _job_alive: sender_alive, job_canceled: receiver_canceled };
18 let handle = JobHandle { job_alive: receiver_alive, _job_canceled: sender_canceled };
19 (handle, token)
20 }
21 pub fn is_alive(&self) -> bool {
22 !is_closed(&self.job_alive)
23 }
24 pub fn cancel(self) {
25 }
26}
27
28impl JobToken {
29 pub fn is_canceled(&self) -> bool {
30 is_closed(&self.job_canceled)
31 }
32}
33
34
35// We don't actually send messages through the channels,
36// and instead just check if the channel is closed,
37// so we use uninhabited enum as a message type
38enum Never {}
39
40/// Nonblocking
41fn is_closed(chan: &Receiver<Never>) -> bool {
42 select! {
43 recv(chan, msg) => match msg {
44 None => true,
45 Some(never) => match never {}
46 }
47 default => false,
48 }
49}
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs
index c25d31f4b..20ddb69d6 100644
--- a/crates/libanalysis/src/lib.rs
+++ b/crates/libanalysis/src/lib.rs
@@ -7,10 +7,13 @@ extern crate libeditor;
7extern crate fst; 7extern crate fst;
8extern crate rayon; 8extern crate rayon;
9extern crate relative_path; 9extern crate relative_path;
10#[macro_use]
11extern crate crossbeam_channel;
10 12
11mod symbol_index; 13mod symbol_index;
12mod module_map; 14mod module_map;
13mod imp; 15mod imp;
16mod job;
14 17
15use std::sync::Arc; 18use std::sync::Arc;
16 19
@@ -22,6 +25,7 @@ pub use libeditor::{
22 StructureNode, LineIndex, FileSymbol, 25 StructureNode, LineIndex, FileSymbol,
23 Runnable, RunnableKind, HighlightedRange, CompletionItem, 26 Runnable, RunnableKind, HighlightedRange, CompletionItem,
24}; 27};
28pub use job::{JobToken, JobHandle};
25 29
26#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 30#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
27pub struct FileId(pub u32); 31pub struct FileId(pub u32);