I have noticed the zip operator executes the corou...
# coroutines
j
I have noticed the zip operator executes the coroutines sequentially, see the following example:
Copy code
flowOf(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.
o
I think you're going for:
Copy code
flow {
  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
)
👍🏻 1
j
Yes, that is it! It works now. Thanks.
m
flowOf is sequential! It won't proceed down the pipeline until the code returns with the value after suspension point i guess