diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs index 90c024f83d..75df325508 100644 --- a/crates/gpui3/src/app.rs +++ b/crates/gpui3/src/app.rs @@ -219,7 +219,7 @@ impl AppContext { f: impl FnOnce(&mut MainThread) -> F + Send + 'static, ) -> Task where - F: Future + Send + 'static, + F: Future + 'static, R: Send + 'static, { let this = self.this.upgrade().unwrap(); diff --git a/crates/gpui3/src/executor.rs b/crates/gpui3/src/executor.rs index d82878cf28..9b2e3ad4c3 100644 --- a/crates/gpui3/src/executor.rs +++ b/crates/gpui3/src/executor.rs @@ -77,13 +77,22 @@ impl Executor { /// closure returns a future which will be run to completion on the main thread. pub fn spawn_on_main(&self, func: impl FnOnce() -> F + Send + 'static) -> Task where - F: Future + Send + 'static, + F: Future + 'static, R: Send + 'static, { - let dispatcher = self.dispatcher.clone(); - let (runnable, task) = async_task::spawn(async move { func().await }, move |runnable| { - dispatcher.dispatch_on_main_thread(runnable) - }); + let (runnable, task) = async_task::spawn( + { + let this = self.clone(); + async move { + let task = this.spawn_on_main_local(func()); + task.await + } + }, + { + let dispatcher = self.dispatcher.clone(); + move |runnable| dispatcher.dispatch_on_main_thread(runnable) + }, + ); runnable.schedule(); Task::Spawned(task) }