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

<lambda>null1 // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleFlow04
3 
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.flow.*
6 
7 fun simple(): Flow<Int> = flow { // flow builder
8     for (i in 1..3) {
9         delay(100) // pretend we are doing something useful here
10         emit(i) // emit next value
11     }
12 }
13 
<lambda>null14 fun main() = runBlocking<Unit> {
15     // Launch a concurrent coroutine to check if the main thread is blocked
16     launch {
17         for (k in 1..3) {
18             println("I'm not blocked $k")
19             delay(100)
20         }
21     }
22     // Collect the flow
23     simple().collect { value -> println(value) }
24 }
25