What is the best current workaround for this: <htt...
# coroutines
w
What is the best current workaround for this: https://github.com/Kotlin/kotlinx.coroutines/issues/1147 I would like to have a flow that launches many async processes in parallel and collects the results into the flow.
d
There are solutions in the issue. Although it depends on your requirements, do you care about order?
w
No, I don't care about the order
d
Then I think you can use
flatMapMerge
.
w
Ok ill look into that, thanks!
hmm, that didnt do it in my case. here is basically what I am doing: I am trying to
doSomething
n times per second for duration seconds:
Copy code
fun doSomething(): List<Thing>

fun s(duration: Duration, n: Int){
    flow {
            val start = Instant.now()
            (0 until duration.seconds).toList().forEach { tick ->
                (1..n).toList().map {
                    delay(start.plusMillis(tick).minusMillis(Instant.now().toEpochMilli()).toEpochMilli())
                    emit(doSomething().asFlow())
                }
            }
    }.flattenMerge(1000)
}
but how do you define what the channel produces?