gildor
08/15/2017, 9:29 AMsuspend fun Db.saveAsync() = async(DbPool) { db.save() }
db.saveAsync().await()
or
suspend fun Db.saveAsync() = run(DbPool) { db.save() }
db.saveAsync()
qwert_ukg
08/18/2017, 5:46 AMgildor
08/18/2017, 5:50 AMdb.saveAsync()
doSomethingElse()
doSomethingElse() will be called after db save will be finishedqwert_ukg
08/18/2017, 5:53 AMdoSomthingElse()
should be suspend
func and should be called into async func?gildor
08/18/2017, 5:54 AMsaveAsync()
doesn’t lock thread from which you called itqwert_ukg
08/18/2017, 10:24 AMsuspend fun NotificationRepository.sendAndSaveAsync(notification: Notification) = run(CommonPool) {
with(notification) {
messageType!!.sender.makeRequest(notification)
responseBody = messageType!!.sender.getResponse(this)
save(this)
}
}!!
async(CommonPool) { saveAsync(notification) }
gildor
08/18/2017, 10:27 AMqwert_ukg
08/18/2017, 10:45 AMnotificationsForSendRequests.forEach {
val json = mockMvc.perform(it)
.andExpect(status().isOk)
.andReturn().response.contentAsString
val identifier = JsonPath.read<Long>(json, "$.identifier")
assertTrue(identifier > 0)
gildor
08/18/2017, 10:59 AMqwert_ukg
08/18/2017, 11:04 AM