From 9922c0e0f5eb338869a33679c5efe43a029d84ac Mon Sep 17 00:00:00 2001 From: John Carmack Date: Tue, 12 Nov 2024 08:31:27 -0800 Subject: [PATCH] Add run_async_command macro for SQL plugin --- plugins/sql/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/sql/src/lib.rs b/plugins/sql/src/lib.rs index 352ffbec..93659098 100644 --- a/plugins/sql/src/lib.rs +++ b/plugins/sql/src/lib.rs @@ -104,6 +104,12 @@ impl MigrationSource<'static> for MigrationList { } } +macro_rules! run_async_command { + ($cmd:expr) => { + tokio::task::block_in_place(|| tokio::runtime::Handle::current().block_on($cmd)) + }; +} + /// Tauri SQL plugin builder. #[derive(Default)] pub struct Builder { @@ -138,7 +144,7 @@ impl Builder { .setup(|app, api| { let config = api.config().clone().unwrap_or_default(); - tauri::async_runtime::block_on(async move { + run_async_command!(async move { let instances = DbInstances::default(); let mut lock = instances.0.write().await; @@ -166,7 +172,7 @@ impl Builder { }) .on_event(|app, event| { if let RunEvent::Exit = event { - tauri::async_runtime::block_on(async move { + run_async_command!(async move { let instances = &*app.state::(); let instances = instances.0.read().await; for value in instances.values() {