Remove all windows before quitting

This gives all entities a chance of running `Drop::drop` which,
in turn, could cause them to spawn a critical task. For example,
we use this capability when a language server is dropped and we
need to asynchronously send a shutdown message.
This commit is contained in:
Antonio Scandurra 2021-11-02 14:55:31 +01:00
parent 61e06487b7
commit f5aa07aac9
2 changed files with 8 additions and 0 deletions

View file

@ -1230,6 +1230,13 @@ impl MutableAppContext {
self.remove_dropped_entities();
}
pub fn remove_all_windows(&mut self) {
for (window_id, _) in self.cx.windows.drain() {
self.presenters_and_platform_windows.remove(&window_id);
}
self.remove_dropped_entities();
}
fn open_platform_window(&mut self, window_id: usize, window_options: WindowOptions) {
let mut window =
self.cx

View file

@ -30,6 +30,7 @@ fn main() {
languages.set_theme(&settings.borrow().theme.editor.syntax);
app.on_quit(|cx| {
cx.remove_all_windows();
let did_finish = cx
.background()
.block_on_critical_tasks(Duration::from_millis(100));