From 8370b3075ee15c0bb946cdd719effe0182aefedd Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 1 Oct 2021 12:00:37 -0700 Subject: [PATCH] Avoid spawn_local instantiations due to different scheduling closure Co-Authored-By: Nathan Sobo --- gpui/src/executor.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/gpui/src/executor.rs b/gpui/src/executor.rs index ba5a88e68e..01338c8a0a 100644 --- a/gpui/src/executor.rs +++ b/gpui/src/executor.rs @@ -23,7 +23,10 @@ use std::{ }; use waker_fn::waker_fn; -use crate::{platform, util}; +use crate::{ + platform::{self, Dispatcher}, + util, +}; pub enum Foreground { Platform { @@ -398,11 +401,18 @@ impl Foreground { let any_task = match self { Self::Deterministic(executor) => executor.spawn_from_foreground(future), Self::Platform { dispatcher, .. } => { - let dispatcher = dispatcher.clone(); - let schedule = move |runnable: Runnable| dispatcher.run_on_main_thread(runnable); - let (runnable, task) = async_task::spawn_local(future, schedule); - runnable.schedule(); - task + fn spawn_inner( + future: AnyLocalFuture, + dispatcher: &Arc, + ) -> AnyLocalTask { + let dispatcher = dispatcher.clone(); + let schedule = + move |runnable: Runnable| dispatcher.run_on_main_thread(runnable); + let (runnable, task) = async_task::spawn_local(future, schedule); + runnable.schedule(); + task + } + spawn_inner(future, dispatcher) } Self::Test(executor) => executor.spawn(future), };