【发布时间】:2020-12-19 22:52:37
【问题描述】:
我使用以下代码时出现编译错误:
只能在协程体内调用挂起函数
谁能给我解释一下为什么?我需要做什么才能使其工作(不使用@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()
}
提前感谢您的帮助
【问题讨论】:
标签: android kotlin kotlin-coroutines coroutine