waltermcq
04/19/2020, 12:25 PMoverride suspend fun newUser(id: String, name: String): UserAgg {
return dbQuery {
val userRow = UserTable.insert {
it[this.id] = id
it[this.name] = name
}.resultedValues!!.first()
getUserById(UserId(userRow[UserTable.id]))!!
}
}
suspend fun <T> dbQuery(
block: () -> T): T =
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
transaction { block() }
}
louiscad
04/19/2020, 12:51 PMblock
lambda of the dbQuery
function is not suspending, that's why.waltermcq
04/19/2020, 3:12 PMblock
lambda suspending?louiscad
04/19/2020, 3:31 PMsuspend
as a prefix in the type of block
, if transaction
takes a suspending lambda. Otherwise, you'll need to slip your code to do it in two steps so there's no suspend call in the transaction.waltermcq
04/19/2020, 3:32 PM