使用以下代码时出现编译错误:
暂停函数只能在协程体内调用
有人可以向我解释为什么吗?我需要做什么才能使它工作(不使用@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()
}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助