George
09/06/2022, 11:39 AMval account = async { getAccountByUuid(accountUUID) }
val devices = async { deviceRepository.findDevicesByUuid(accountUUID) }
account.await()?.addDevices(devices.await()) ?: return@coroutineScope null
In case the account.await() is null, the devices.await() is still waiting or it is just canceled ? I believe it is canceled but just want to make it sure. Thanks in advance for any answers !Sam
09/06/2022, 11:41 AMcoroutineScope { … }
block here? In that case, even though you don’t reach the call to devices.await()
, the scope will still wait for all of its children to complete before it returns.George
09/06/2022, 12:17 PMoverride suspend fun getAccountByUuidWithDevices(accountUUID: UUID): Account? = coroutineScope {
val account = async { getAccountByUuid(accountUUID) }
val devices = async { deviceRepository.findDevicesByUuid(accountUUID) }
val accountResult = account.await()
if (accountResult == null) {
devices.cancel()
return@coroutineScope null
}
accountResult.addDevices(devices.await())
}
in that case is it even worth it to cancel it manually rather than just executing sequential ? they are both db calls.Sam
09/06/2022, 12:19 PMJoffrey
09/06/2022, 12:22 PMasync
for getAccount
- just call it directly where you currently await the corresponding deferred