From ecf42b97df85df25b1b825f37adfeb00f658f6ee Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 7 Mar 2024 23:25:24 +0100 Subject: Fix `block_on` in `iced_wgpu` hanging Wasm builds --- src/application.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 3d89c758..87c2607a 100644 --- a/src/application.rs +++ b/src/application.rs @@ -205,11 +205,26 @@ pub trait Application: Sized { ..crate::renderer::Settings::default() }; - Ok(crate::shell::application::run::< + let run = crate::shell::application::run::< Instance, Self::Executor, crate::renderer::Compositor, - >(settings.into(), renderer_settings)?) + >(settings.into(), renderer_settings); + + #[cfg(target_arch = "wasm32")] + { + use crate::futures::FutureExt; + use iced_futures::backend::wasm::wasm_bindgen::Executor; + + Executor::new() + .expect("Create Wasm executor") + .spawn(run.map(|_| ())); + + Ok(()) + } + + #[cfg(not(target_arch = "wasm32"))] + Ok(crate::futures::executor::block_on(run)?) } } -- cgit