Add run_async_command macro for SQL plugin

pull/2038/head
John Carmack 9 months ago
parent 371a2f7361
commit 9922c0e0f5
No known key found for this signature in database

@ -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::<DbInstances>();
let instances = instances.0.read().await;
for value in instances.values() {

Loading…
Cancel
Save