-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sql) Allow tauri-plugin-sql to work when Tauri is running async #2038
fix(sql) Allow tauri-plugin-sql to work when Tauri is running async #2038
Conversation
Makes me wonder why we didn't make https://github.com/tauri-apps/tauri/blob/dev/crates%2Ftauri%2Fsrc%2Fasync_runtime.rs#L288 the default 🤔 |
Actually, I think having a centralized approach would be better, this could happen in every plugin because they kinda as expect a sync main fn |
@amrbashir do you think pub exposing safe_block_on in core makes sense? |
Package Changes Through 837f1e9There are 10 changes which include upload with minor, upload-js with minor, deep-link with patch, deep-link-js with patch, log-plugin with patch, log-js with patch, fs with patch, fs-js with patch, localhost with minor, sql with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
maybe, idk, I don't use async that much |
okay no problem, let's keep it plugin-local for now and see if this gets more common. @johncarmack1984 would you mind checking if the safe_block_on approach also works here? I assume there's a reason it doesn't use block_in_place. Also, i think a code comment explaining why this was added (so nobody removes it by accident) would be valuable. And idk if it's just me but i'd rather not solve this with a macro but just a simple function call if there's no good reason for a macro. Lastly, we'll also need a changefile. |
Sure thing! If I clone Tauri locally and modify
I'll add an explainer comment and get started on a changefile, hopefully will have it later today! Will also see if functionality is preserved when using a function vs a macro and report back if not. |
Success converting macro to function, have added changefile and explainer comment! Please let me know if I can provide anything else! :) |
Okay now i remember why safe_block_on was bigger than that. Your change currently panics in sync contexts. |
Oof... yikes, I'll take another crack at it. Any initial thoughts on approaches that might satisfy both? If not I'll troubleshoot it today. |
a modified version of safe_block_on. Using Handle::try_current to check if there's a runtime and then using block_in_place or block_on directly. |
Worked a charm; sync and async both operating locally. Thanks for catching that! |
At present,
tauri-plugin-sql
only works when the main Tauri thread is using the default, synchronous runtime.In certain configurations, running Tauri asynchronously can be necessary, ie when using TaurPC or other dependencies that require it.
With the current configuration, running Tauri asynchronously while trying to use
tauri-plugin-sql
yields this error:By changing the
block_on
function call insql/lib.rs
to the macro provided, the plugin works flawlessly, in both synchronous and asynchronous runtimes.Please let me know if more information is needed!