Jamie Craane
07/05/2020, 4:45 PMflowOf(getWeather(loc)).zip(flowOf(reverseGeocode(loc))) { weather, address ->
weather to address
}
.flowOn(Dispatchers.Default)
.collect { println(it) }
The time it takes to execute this is the total time of the getWeather and reverseGeocode calls combined. I know I can use a map
operator and two async/wait blocks to execute the two calls asynchronously. Is it possible to execute multiple coroutines
like this with flow operators? I tried a couple of different things but without success?
I saw https://github.com/Kotlin/kotlinx.coroutines/issues/1147 so perhaps all operators are sequential for now.octylFractal
07/05/2020, 6:46 PMflow {
getWeather(loc)
}.zip(flow {
reverseGeocode(loc)
})
you need to put each call inside the flows, not directly in the arguments, otherwise it's just as if you called them in sequence (just like without suspend
)Jamie Craane
07/05/2020, 7:18 PMmyanmarking
07/07/2020, 8:51 AM