https://kotlinlang.org logo
#coroutines
Title
# coroutines
w

wakingrufus

10/04/2019, 2:31 PM
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

Dominaezzz

10/04/2019, 4:15 PM
There are solutions in the issue. Although it depends on your requirements, do you care about order?
w

wakingrufus

10/04/2019, 4:49 PM
No, I don't care about the order
d

Dominaezzz

10/04/2019, 4:50 PM
Then I think you can use
flatMapMerge
.
w

wakingrufus

10/04/2019, 5:03 PM
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?
2 Views