Skip to content
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

"generateAsync = true" doesn't work #113

Open
armond-avanes opened this issue Mar 28, 2024 · 3 comments
Open

"generateAsync = true" doesn't work #113

armond-avanes opened this issue Mar 28, 2024 · 3 comments

Comments

@armond-avanes
Copy link

armond-avanes commented Mar 28, 2024

When I enable async in the database definition in my build file, I can't get my code compiled because an async version of Database.schema is generated and SQLiteMCDriver.Factory(...) doesn't accept any such schema.

sqliteMC {
    databases {
        create("Database") {
            packageName.set("com.my.package.name")
            generateAsync = true
        }
    }
}
@05nelsonm
Copy link
Collaborator

Will have to add. PRs welcome!

I am curious about your setup, though. Do you have JS targets for your project?

The only reason for using generateAsync = true is if you have JS source sets, which this repository does not support. For non-js, the async schema simply calls the non-async functions under the hood with no context switching to execute on a BG thread. There is no benefit to using it for non-js, as you'd still have to wrap all calls (suspending or not) in withContext blocks, providing it your desired dispatcher.

@armond-avanes
Copy link
Author

armond-avanes commented Apr 2, 2024

@05nelsonm I don't have any JS/Web target in my project.

What I'm trying to achieve here is to get coroutine support (suspend functions) for insert, update and delete statements (plus transactions). With the current support for flows, I could only apply it to my queries. I thought generateAsync = true could do it.

Please let me know if I'm missing anything here and the support is already there for having suspend insert/update/delete/transaction statements.

@05nelsonm
Copy link
Collaborator

So the generateAsync functionality is only there to support JS. For non-js targets, those generated suspend functions will call the underlying blocking (non-suspending) functions. The suspend functions do NOT switch dispatchers to a BG thread or anything, they are purely for supporting JS targets.

If you do not have js/web targets, set generateAsync to false and simply call the non-suspending function from your suspend functions in the appropriated thread context (e.g. Dispatchers.IO.limitedParallelism(1))

Again, contributions via PRs are always welcomed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants