xref: /aosp_15_r20/external/kotlinx.coroutines/kotlinx-coroutines-core/jvm/test/guide/example-flow-24.kt (revision 7a7160fed73afa6648ef8aa100d4a336fe921d9a)

<lambda>null1 // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleFlow24
3 
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.flow.*
6 
7 fun requestFlow(i: Int): Flow<String> = flow {
8     emit("$i: First")
9     delay(500) // wait 500 ms
10     emit("$i: Second")
11 }
12 
<lambda>null13 fun main() = runBlocking<Unit> {
14     val startTime = currentTimeMillis() // remember the start time
15     (1..3).asFlow().onEach { delay(100) } // a number every 100 ms
16         .flatMapMerge { requestFlow(it) }
17         .collect { value -> // collect and print
18             println("$value at ${currentTimeMillis() - startTime} ms from start")
19         }
20 }
21