wakingrufus
10/04/2019, 2:31 PMDominaezzz
10/04/2019, 4:15 PMwakingrufus
10/04/2019, 4:49 PMDominaezzz
10/04/2019, 4:50 PMflatMapMerge
.wakingrufus
10/04/2019, 5:03 PMdoSomething
n times per second for duration seconds:
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)
}