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

<lambda>null1 // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleFlow10
3 
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.flow.*
6 
7 fun numbers(): Flow<Int> = flow {
8     try {
9         emit(1)
10         emit(2)
11         println("This line will not execute")
12         emit(3)
13     } finally {
14         println("Finally in numbers")
15     }
16 }
17 
<lambda>null18 fun main() = runBlocking<Unit> {
19     numbers()
20         .take(2) // take only the first two
21         .collect { value -> println(value) }
22 }
23