Status Update
Comments
yb...@google.com <yb...@google.com> #2
seems like the error is mentioning LiveData by mistake instead of suspend.
Seems like we should actually allow suspend functions once we have a suspend version of the runInTransaction.
Seems like we should actually allow suspend functions once we have a suspend version of the runInTransaction.
Description
Version used: 2.1.0-alpha04
Devices/Android versions reproduced on: Pixel 2 XL, Android Pie
Refer to the project at
@Entity
data class Info ( @PrimaryKey val name : String )
@Dao
abstract class InfoDao {
@Insert
abstract suspend fun insert( info : Info )
@Query( "DELETE FROM Info" )
abstract suspend fun deleteAll()
@Transaction
open suspend fun deleteAllAndInsert( info : Info ) {
deleteAll()
insert( info )
}
}
Compilation fails with this even though deleteAllAndInsert returns Unit
Method annotated with @Transaction must not return deferred/async return type androidx.lifecycle.LiveData. Since transactions are thread confined and Room cannot guarantee that all queries in the method implementation are performed on the same thread, only synchronous @Transaction implemented methods are allowed. If a transaction is started and a change of thread is done and waited upon then a database deadlock can occur if the additional thread attempts to perform a query. This restrictions prevents such situation from occurring.