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 AMgildor
08/18/2017, 5:54 AMsaveAsync()
doesn’t lock thread from which you called itgildor
08/18/2017, 5:55 AMqwert_ukg
08/18/2017, 10:24 AMqwert_ukg
08/18/2017, 10:25 AMqwert_ukg
08/18/2017, 10:25 AMsuspend fun NotificationRepository.sendAndSaveAsync(notification: Notification) = run(CommonPool) {
with(notification) {
messageType!!.sender.makeRequest(notification)
responseBody = messageType!!.sender.getResponse(this)
save(this)
}
}!!
qwert_ukg
08/18/2017, 10:26 AMasync(CommonPool) { saveAsync(notification) }
gildor
08/18/2017, 10:27 AMgildor
08/18/2017, 10:28 AMgildor
08/18/2017, 10:29 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)
qwert_ukg
08/18/2017, 10:46 AMgildor
08/18/2017, 10:59 AMqwert_ukg
08/18/2017, 11:04 AMqwert_ukg
08/18/2017, 11:05 AM