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 {
102102 }
103103}
104104
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+
105114/// Tauri SQL plugin builder.
106115#[ derive( Default ) ]
107116pub struct Builder {
@@ -136,7 +145,7 @@ impl Builder {
136145 . setup ( |app, api| {
137146 let config = api. config ( ) . clone ( ) . unwrap_or_default ( ) ;
138147
139- tauri :: async_runtime :: block_on ( async move {
148+ run_async_command ( async move {
140149 let instances = DbInstances :: default ( ) ;
141150 let mut lock = instances. 0 . write ( ) . await ;
142151
@@ -164,7 +173,7 @@ impl Builder {
164173 } )
165174 . on_event ( |app, event| {
166175 if let RunEvent :: Exit = event {
167- tauri :: async_runtime :: block_on ( async move {
176+ run_async_command ( async move {
168177 let instances = & * app. state :: < DbInstances > ( ) ;
169178 let instances = instances. 0 . read ( ) . await ;
170179 for value in instances. values ( ) {
You can’t perform that action at this time.
0 commit comments