File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " sql " : " patch"
3
+ ---
4
+
5
+ Allow blocking on async code without creating a nested runtime.
Original file line number Diff line number Diff line change @@ -102,6 +102,15 @@ impl MigrationSource<'static> for MigrationList {
102
102
}
103
103
}
104
104
105
+ /// Allows blocking on async code without creating a nested runtime.
106
+ fn run_async_command < F : std:: future:: Future > ( cmd : F ) -> F :: Output {
107
+ if tokio:: runtime:: Handle :: try_current ( ) . is_ok ( ) {
108
+ tokio:: task:: block_in_place ( || tokio:: runtime:: Handle :: current ( ) . block_on ( cmd) )
109
+ } else {
110
+ tauri:: async_runtime:: block_on ( cmd)
111
+ }
112
+ }
113
+
105
114
/// Tauri SQL plugin builder.
106
115
#[ derive( Default ) ]
107
116
pub struct Builder {
@@ -136,7 +145,7 @@ impl Builder {
136
145
. setup ( |app, api| {
137
146
let config = api. config ( ) . clone ( ) . unwrap_or_default ( ) ;
138
147
139
- tauri :: async_runtime :: block_on ( async move {
148
+ run_async_command ( async move {
140
149
let instances = DbInstances :: default ( ) ;
141
150
let mut lock = instances. 0 . write ( ) . await ;
142
151
@@ -164,7 +173,7 @@ impl Builder {
164
173
} )
165
174
. on_event ( |app, event| {
166
175
if let RunEvent :: Exit = event {
167
- tauri :: async_runtime :: block_on ( async move {
176
+ run_async_command ( async move {
168
177
let instances = & * app. state :: < DbInstances > ( ) ;
169
178
let instances = instances. 0 . read ( ) . await ;
170
179
for value in instances. values ( ) {
You can’t perform that action at this time.
0 commit comments