How to add async/await inside the listen events #4959
-
I would like to close my database when the app closes, but can't quit figure out how to do it - here's what i've got. This compiles but panics at runtime : 'Cannot start a runtime from within a runtime. This happens because a function (like
this question was essentially asked here (but there was no final resolution): Any advice would be greatly appreciated - thanks - |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The last messages in that thread go somewhat in the right direction. 1) It's actually quite rare that you really need tokio::main _in a tauri app. 2) if you still want to do it (which is fine btw), you need to give Tauri a handle to the tokio runtime: https://docs.rs/tauri/latest/tauri/async_runtime/fn.set.html Edit: It gets a little weird inside the on_X_event handlers, you need to wrap the async_runtime::block_on call in |
Beta Was this translation helpful? Give feedback.
-
FabianLars figured out a solution here - wrap the block_on call in tokio::task::block_in_place |
Beta Was this translation helpful? Give feedback.
The last messages in that thread go somewhat in the right direction. 1) It's actually quite rare that you really need tokio::main _in a tauri app. 2) if you still want to do it (which is fine btw), you need to give Tauri a handle to the tokio runtime: https://docs.rs/tauri/latest/tauri/async_runtime/fn.set.html
Edit: It gets a little weird inside the on_X_event handlers, you need to wrap the async_runtime::block_on call in
tauri::task::block_in_place
:/