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

<lambda>null1 // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleFlow29
3 
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.flow.*
6 
7 fun simple(): Flow<Int> = flow {
8     for (i in 1..3) {
9         println("Emitting $i")
10         emit(i)
11     }
12 }
13 
<lambda>null14 fun main() = runBlocking<Unit> {
15     simple()
16         .catch { e -> println("Caught $e") } // does not catch downstream exceptions
17         .collect { value ->
18             check(value <= 1) { "Collected $value" }
19             println(value)
20         }
21 }
22