From b5021411a84822cb3f1e3aeffad9550dd15bdeb6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Sep 2018 12:54:24 +0300 Subject: rename all things --- crates/ra_analysis/src/job.rs | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 crates/ra_analysis/src/job.rs (limited to 'crates/ra_analysis/src/job.rs') diff --git a/crates/ra_analysis/src/job.rs b/crates/ra_analysis/src/job.rs new file mode 100644 index 000000000..ea1652a26 --- /dev/null +++ b/crates/ra_analysis/src/job.rs @@ -0,0 +1,49 @@ +use crossbeam_channel::{bounded, Receiver, Sender}; + +pub struct JobHandle { + job_alive: Receiver, + _job_canceled: Sender, +} + +pub struct JobToken { + _job_alive: Sender, + job_canceled: Receiver, +} + +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 has_completed(&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) -> bool { + select! { + recv(chan, msg) => match msg { + None => true, + Some(never) => match never {} + } + default => false, + } +} -- cgit v1.2.3