Avoid runBlocking

This commit is contained in:
Mygod
2019-08-12 13:13:29 +08:00
parent 05a79acf78
commit 3770acf561
4 changed files with 14 additions and 10 deletions

View File

@@ -12,6 +12,10 @@ data class ClientRecord(@PrimaryKey
var macLookupPending: Boolean = true) {
@androidx.room.Dao
abstract class Dao {
@Query("SELECT * FROM `ClientRecord` WHERE `mac` = :mac")
protected abstract fun lookupBlocking(mac: Long): ClientRecord?
fun lookupOrDefaultBlocking(mac: Long) = lookupBlocking(mac) ?: ClientRecord(mac)
@Query("SELECT * FROM `ClientRecord` WHERE `mac` = :mac")
protected abstract suspend fun lookup(mac: Long): ClientRecord?
suspend fun lookupOrDefault(mac: Long) = lookup(mac) ?: ClientRecord(mac)

View File

@@ -41,8 +41,8 @@ data class TrafficRecord(
@androidx.room.Dao
abstract class Dao {
@Insert
protected abstract suspend fun insertInternal(value: TrafficRecord): Long
suspend fun insert(value: TrafficRecord) {
protected abstract fun insertInternal(value: TrafficRecord): Long
fun insert(value: TrafficRecord) {
check(value.id == null)
value.id = insertInternal(value)
}