coroutineScope {
val oreoFeaturesDeferred = async { mockApi.getAndroidVersionFeatures(27) }
val pieFeaturesDeferred = async { mockApi.getAndroidVersionFeatures(28) }
val android10FeaturesDeferred = async { mockApi.getAndroidVersionFeatures(29) }
val oreoFeatures = oreoFeaturesDeferred.await()
val pieFeatures = pieFeaturesDeferred.await()
val android10Features = android10FeaturesDeferred.await()
val versionFeatures = listOf(oreoFeatures, pieFeatures, android10Features)
// other alternative: (but slightly different behavior when a deferred fails, see docs)
// val versionFeatures = awaitAll(oreoFeaturesDeferred, pieFeaturesDeferred, android10FeaturesDeferred)
uiState.value = UiState.Success(versionFeatures)
}
i have some question about this code, deferred's await() function will suspend this coroutines, so this demo code can't performed in parallel
i have some question about this code, deferred's await() function will suspend this coroutines, so this demo code can't performed in parallel