diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 94fdab8927aadd9b091973bac4b9da7d27e1edab..4e2cf10ebfc50316596bb71b1bc83f043a9c900d 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1462,29 +1462,33 @@ impl App { cx.window_update_stack.push(window.handle.id); let result = update(root_view, &mut window, cx); - cx.window_update_stack.pop(); + fn trail(id: WindowId, window: Box, cx: &mut App) -> Option<()> { + cx.window_update_stack.pop(); - if window.removed { - cx.window_handles.remove(&id); - cx.windows.remove(id); + if window.removed { + cx.window_handles.remove(&id); + cx.windows.remove(id); - cx.window_closed_observers.clone().retain(&(), |callback| { - callback(cx); - true - }); + cx.window_closed_observers.clone().retain(&(), |callback| { + callback(cx); + true + }); - let quit_on_empty = match cx.quit_mode { - QuitMode::Explicit => false, - QuitMode::LastWindowClosed => true, - QuitMode::Default => cfg!(not(target_os = "macos")), - }; + let quit_on_empty = match cx.quit_mode { + QuitMode::Explicit => false, + QuitMode::LastWindowClosed => true, + QuitMode::Default => cfg!(not(target_os = "macos")), + }; - if quit_on_empty && cx.windows.is_empty() { - cx.quit(); + if quit_on_empty && cx.windows.is_empty() { + cx.quit(); + } + } else { + cx.windows.get_mut(id)?.replace(window); } - } else { - cx.windows.get_mut(id)?.replace(window); + Some(()) } + trail(id, window, cx)?; Some(result) }) @@ -1529,7 +1533,7 @@ impl App { let mut cx = self.to_async(); self.foreground_executor - .spawn(async move { f(&mut cx).await }) + .spawn(async move { f(&mut cx).await }.boxed_local()) } /// Spawns the future returned by the given function on the main thread with @@ -1547,7 +1551,7 @@ impl App { let mut cx = self.to_async(); self.foreground_executor - .spawn_with_priority(priority, async move { f(&mut cx).await }) + .spawn_with_priority(priority, async move { f(&mut cx).await }.boxed_local()) } /// Schedules the given function to be run at the end of the current effect cycle, allowing entities diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rs index ed202f6b86b6edd812d50f7fa975fbd5def9ae62..c770e8c03ab8431fa529ee23c06ffaac50ae8204 100644 --- a/crates/gpui/src/app/async_context.rs +++ b/crates/gpui/src/app/async_context.rs @@ -7,6 +7,7 @@ use crate::{ use anyhow::Context as _; use derive_more::{Deref, DerefMut}; use futures::channel::oneshot; +use smol::future::FutureExt; use std::{future::Future, rc::Weak}; use super::{Context, WeakEntity}; @@ -184,7 +185,7 @@ impl AsyncApp { { let mut cx = self.clone(); self.foreground_executor - .spawn(async move { f(&mut cx).await }) + .spawn(async move { f(&mut cx).await }.boxed_local()) } /// Determine whether global state of the specified type has been assigned. @@ -322,7 +323,7 @@ impl AsyncWindowContext { { let mut cx = self.clone(); self.foreground_executor - .spawn(async move { f(&mut cx).await }) + .spawn(async move { f(&mut cx).await }.boxed_local()) } /// Present a platform dialog. diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index 9ff4a9e196d7fda25fa709dc628674099a38a758..36faf52e74ef2d7653adfc98a09435c09f6604ec 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -145,7 +145,7 @@ impl BackgroundExecutor { where R: Send + 'static, { - self.spawn_with_priority(Priority::default(), future) + self.spawn_with_priority(Priority::default(), future.boxed()) } /// Enqueues the given future to be run to completion on a background thread with the given priority. @@ -409,7 +409,7 @@ impl ForegroundExecutor { where R: 'static, { - Task::from_scheduler(self.inner.spawn(future)) + Task::from_scheduler(self.inner.spawn(future.boxed_local())) } /// Enqueues the given Task to run on the main thread with the given priority.