mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
cancelation tokens
This commit is contained in:
parent
902df0fc05
commit
efa6a952b4
3 changed files with 54 additions and 0 deletions
|
@ -6,6 +6,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
relative-path = "0.3.7"
|
relative-path = "0.3.7"
|
||||||
log = "0.4.2"
|
log = "0.4.2"
|
||||||
|
crossbeam-channel = "0.2.4"
|
||||||
parking_lot = "0.6.3"
|
parking_lot = "0.6.3"
|
||||||
once_cell = "0.1.4"
|
once_cell = "0.1.4"
|
||||||
rayon = "1.0.2"
|
rayon = "1.0.2"
|
||||||
|
|
49
crates/libanalysis/src/job.rs
Normal file
49
crates/libanalysis/src/job.rs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
|
|
||||||
|
pub struct JobHandle {
|
||||||
|
job_alive: Receiver<Never>,
|
||||||
|
_job_canceled: Sender<Never>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct JobToken {
|
||||||
|
_job_alive: Sender<Never>,
|
||||||
|
job_canceled: Receiver<Never>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JobHandle {
|
||||||
|
pub fn new() -> (JobHandle, JobToken) {
|
||||||
|
let (sender_alive, receiver_alive) = bounded(0);
|
||||||
|
let (sender_canceled, receiver_canceled) = bounded(0);
|
||||||
|
let token = JobToken { _job_alive: sender_alive, job_canceled: receiver_canceled };
|
||||||
|
let handle = JobHandle { job_alive: receiver_alive, _job_canceled: sender_canceled };
|
||||||
|
(handle, token)
|
||||||
|
}
|
||||||
|
pub fn is_alive(&self) -> bool {
|
||||||
|
!is_closed(&self.job_alive)
|
||||||
|
}
|
||||||
|
pub fn cancel(self) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JobToken {
|
||||||
|
pub fn is_canceled(&self) -> bool {
|
||||||
|
is_closed(&self.job_canceled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// We don't actually send messages through the channels,
|
||||||
|
// and instead just check if the channel is closed,
|
||||||
|
// so we use uninhabited enum as a message type
|
||||||
|
enum Never {}
|
||||||
|
|
||||||
|
/// Nonblocking
|
||||||
|
fn is_closed(chan: &Receiver<Never>) -> bool {
|
||||||
|
select! {
|
||||||
|
recv(chan, msg) => match msg {
|
||||||
|
None => true,
|
||||||
|
Some(never) => match never {}
|
||||||
|
}
|
||||||
|
default => false,
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,10 +7,13 @@ extern crate libeditor;
|
||||||
extern crate fst;
|
extern crate fst;
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
extern crate relative_path;
|
extern crate relative_path;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate crossbeam_channel;
|
||||||
|
|
||||||
mod symbol_index;
|
mod symbol_index;
|
||||||
mod module_map;
|
mod module_map;
|
||||||
mod imp;
|
mod imp;
|
||||||
|
mod job;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -22,6 +25,7 @@ pub use libeditor::{
|
||||||
StructureNode, LineIndex, FileSymbol,
|
StructureNode, LineIndex, FileSymbol,
|
||||||
Runnable, RunnableKind, HighlightedRange, CompletionItem,
|
Runnable, RunnableKind, HighlightedRange, CompletionItem,
|
||||||
};
|
};
|
||||||
|
pub use job::{JobToken, JobHandle};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct FileId(pub u32);
|
pub struct FileId(pub u32);
|
||||||
|
|
Loading…
Reference in a new issue