Explicitly shut down language servers when quitting the app

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo 2021-11-02 13:16:25 -06:00
parent 882c8ce696
commit 2c57703ad6
5 changed files with 161 additions and 102 deletions

View file

@ -40,11 +40,9 @@ pub enum Foreground {
pub enum Background {
Deterministic {
executor: Arc<Deterministic>,
critical_tasks: Mutex<Vec<Task<()>>>,
},
Production {
executor: Arc<smol::Executor<'static>>,
critical_tasks: Mutex<Vec<Task<()>>>,
_stop: channel::Sender<()>,
},
}
@ -504,7 +502,6 @@ impl Background {
Self::Production {
executor,
critical_tasks: Default::default(),
_stop: stop.0,
}
}
@ -526,31 +523,6 @@ impl Background {
Task::send(any_task)
}
pub fn spawn_critical<T, F>(&self, future: F)
where
T: 'static + Send,
F: Send + Future<Output = T> + 'static,
{
let task = self.spawn(async move {
future.await;
});
match self {
Self::Production { critical_tasks, .. }
| Self::Deterministic { critical_tasks, .. } => critical_tasks.lock().push(task),
}
}
pub fn block_on_critical_tasks(&self, timeout: Duration) -> bool {
match self {
Background::Production { critical_tasks, .. }
| Self::Deterministic { critical_tasks, .. } => {
let tasks = mem::take(&mut *critical_tasks.lock());
self.block_with_timeout(timeout, futures::future::join_all(tasks))
.is_ok()
}
}
}
pub fn block_with_timeout<F, T>(
&self,
timeout: Duration,
@ -617,10 +589,7 @@ pub fn deterministic(seed: u64) -> (Rc<Foreground>, Arc<Background>) {
let executor = Arc::new(Deterministic::new(seed));
(
Rc::new(Foreground::Deterministic(executor.clone())),
Arc::new(Background::Deterministic {
executor,
critical_tasks: Default::default(),
}),
Arc::new(Background::Deterministic { executor }),
)
}