使用以下代码时出现编译错误:
Suspension functions can be called only within coroutine body
有人能给我解释一下为什么吗?我需要做什么才能使它工作(不使用@Transaction
注释)?
override suspend fun replaceAccounts(newAccounts: List<Account>) {
database.runInTransaction {
database.accountDao().deleteAllAccounts() // I have the error on this line
database.accountDao().insertAccounts(newAccounts) // Here too
}
}
@Dao
abstract class AccountDao : BaseDao<AccountEntity> {
@Query("DELETE FROM Account")
abstract suspend fun deleteAllAccounts()
}
Thanks in advance for your help