From 4cba370a592894f7094bac3949969a1dd7ee15ce Mon Sep 17 00:00:00 2001 From: temeddix Date: Sat, 15 Jun 2024 20:49:20 +0900 Subject: [PATCH] Ease the return type of the main Rust function --- rust_crate/src/interface.rs | 4 ++-- rust_crate/src/interface_os.rs | 6 ++++-- rust_crate/src/interface_web.rs | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rust_crate/src/interface.rs b/rust_crate/src/interface.rs index 880cf91e..0b1d8fcb 100644 --- a/rust_crate/src/interface.rs +++ b/rust_crate/src/interface.rs @@ -28,7 +28,7 @@ pub struct DartSignal { #[cfg(not(target_family = "wasm"))] pub fn start_rust_logic(main_future: F) -> Result<()> where - F: Future + Send + 'static, + F: Future + Send + 'static, { start_rust_logic_real(main_future) } @@ -39,7 +39,7 @@ where #[cfg(target_family = "wasm")] pub fn start_rust_logic(main_future: F) -> Result<()> where - F: Future + 'static, + F: Future + 'static, { start_rust_logic_real(main_future) } diff --git a/rust_crate/src/interface_os.rs b/rust_crate/src/interface_os.rs index 047e49eb..11851af7 100644 --- a/rust_crate/src/interface_os.rs +++ b/rust_crate/src/interface_os.rs @@ -31,7 +31,7 @@ static TOKIO_RUNTIME: TokioRuntime = OnceLock::new(); pub fn start_rust_logic_real(main_future: F) -> Result<()> where - F: Future + Send + 'static, + F: Future + Send + 'static, { // Enable backtrace output for panics. #[cfg(debug_assertions)] @@ -52,7 +52,9 @@ where let tokio_runtime = Builder::new_multi_thread().enable_all().build()?; // Run the main function. - tokio_runtime.spawn(main_future); + tokio_runtime.spawn(async { + main_future.await; + }); TOKIO_RUNTIME .get_or_init(|| ThreadLocal::new(|| RefCell::new(None))) .with(move |cell| { diff --git a/rust_crate/src/interface_web.rs b/rust_crate/src/interface_web.rs index 9bb6e0f9..e8cc4330 100644 --- a/rust_crate/src/interface_web.rs +++ b/rust_crate/src/interface_web.rs @@ -6,7 +6,7 @@ use wasm_bindgen_futures::spawn_local; pub fn start_rust_logic_real(main_future: F) -> Result<()> where - F: Future + 'static, + F: Future + 'static, { // Add kind description for panics. #[cfg(debug_assertions)] @@ -17,7 +17,9 @@ where } // Run the main function. - spawn_local(main_future); + spawn_local(async { + main_future.await; + }); Ok(()) }