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

<lambda>null1 // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleFlow22
3 
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.flow.*
6 
7 fun main() = runBlocking<Unit> {
8     val nums = (1..3).asFlow().onEach { delay(300) } // numbers 1..3 every 300 ms
9     val strs = flowOf("one", "two", "three").onEach { delay(400) } // strings every 400 ms
10     val startTime = currentTimeMillis() // remember the start time
11     nums.combine(strs) { a, b -> "$a -> $b" } // compose a single string with "combine"
12         .collect { value -> // collect and print
13             println("$value at ${currentTimeMillis() - startTime} ms from start")
14         }
15 }
16