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

<lambda>null1 // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleFlow17
3 
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.flow.*
6 import kotlin.system.*
7 
8 fun simple(): Flow<Int> = flow {
9     for (i in 1..3) {
10         delay(100) // pretend we are asynchronously waiting 100 ms
11         emit(i) // emit next value
12     }
13 }
14 
<lambda>null15 fun main() = runBlocking<Unit> {
16     val time = measureTimeMillis {
17         simple()
18             .buffer() // buffer emissions, don't wait
19             .collect { value ->
20                 delay(300) // pretend we are processing it for 300 ms
21                 println(value)
22             }
23     }
24     println("Collected in $time ms")
25 }
26