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

<lambda>null1 // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleFlow28
3 
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.flow.*
6 
7 fun simple(): Flow<String> =
8     flow {
9         for (i in 1..3) {
10             println("Emitting $i")
11             emit(i) // emit next value
12         }
13     }
valuenull14     .map { value ->
15         check(value <= 1) { "Crashed on $value" }
16         "string $value"
17     }
18 
<lambda>null19 fun main() = runBlocking<Unit> {
20     simple()
21         .catch { e -> emit("Caught $e") } // emit on exception
22         .collect { value -> println(value) }
23 }
24