-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Error when use suspend function with room dao methods #231
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
Comments
Adding the this kotlin signature: |
Does it mean that I can not use |
I see. I will call it in coroutine functions instead. Many thanks! |
As far as I now, yes. At least if you use a library to generate the dao classes. But you can still provider helper on it. interface EventStore {
@Query("select * from myevent")
fun all(): List<MyEvent>
}
// run async and await the result
suspend fun EventStore.awaitAll(): List<MyEvent> = async { all() }.await()
// ensure to run in a given context
suspend fun EventStore.awaitAll(): List<MyEvent> = withContext(CommonPool) { all() } This are just a examples, it depends on what you really want to achieve. |
And of course depending on library you use (especially if it is a Kotlin library), You may ask them to support suspending functions. Or even, improve the library yourself. What is the library you use, if I may ask ? Spring ? If it's spring, it looks like they decided to support Kotlin (https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0), they may support this use case, in the future. |
@jcornaz I'm using Room Persistence library for Android. So now I'm using |
where you able to resolve this issue? I have the same problems and can't figure out a solution |
I'm trying to make all database query / delete functions in the Dao class as suspend functions. I enabled kotlin coroutine in gradle, and add suspend keywork for all dao functions. Then build, and get errors for wrong param type for the auto generated dao methods.
In Dao class:
Then build and get this error:
Error links navigate to code from the auto generated dao class:
I tried delete the generated dao class and rebuild to renegerate it, still get these errors. How can I fix this?
The text was updated successfully, but these errors were encountered: