Zip network requests via Kotlin Coroutine Flow
val dateFlow = flowOf(repository.requestDate())
val timeFlow = flowOf(repository.requestTime())
val zippedFlow = dateFlow.zip(timeFlow) { date, time -> Result(date, time) }
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/zip.html
For most operations Flow
follows the same rules as normal co-routines, so to zip two separate requests you need to apply the async concurrency pattern.
In practise this will end up looking like this:
flow {
emit(coroutineScope/withContext(SomeDispatcher) {
val date = async { repository.requestDate() }
val time = async { repository.requestTime() }
Result(date.await(), time.await())
})
}