Add explainer comment, convert macro to function, and add changefile.

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

@ -0,0 +1,5 @@
---
"sql": "patch"
---
Allow blocking on async code without creating a nested runtime.

@ -104,10 +104,9 @@ impl MigrationSource<'static> for MigrationList {
}
}
macro_rules! run_async_command {
($cmd:expr) => {
tokio::task::block_in_place(|| tokio::runtime::Handle::current().block_on($cmd))
};
/// Allows blocking on async code without creating a nested runtime.
fn run_async_command<F: std::future::Future>(cmd: F) -> F::Output {
tokio::task::block_in_place(|| tokio::runtime::Handle::current().block_on(cmd))
}
/// Tauri SQL plugin builder.
@ -144,7 +143,7 @@ impl Builder {
.setup(|app, api| {
let config = api.config().clone().unwrap_or_default();
run_async_command!(async move {
run_async_command(async move {
let instances = DbInstances::default();
let mut lock = instances.0.write().await;
@ -172,7 +171,7 @@ impl Builder {
})
.on_event(|app, event| {
if let RunEvent::Exit = event {
run_async_command!(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