1 /* <lambda>null2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 // This file was automatically generated from flow.md by Knit tool. Do not edit. 6 package kotlinx.coroutines.guide.exampleFlow25 7 8 import kotlinx.coroutines.* 9 import kotlinx.coroutines.flow.* 10 11 fun requestFlow(i: Int): Flow<String> = flow { 12 emit("$i: First") 13 delay(500) // wait 500 ms 14 emit("$i: Second") 15 } 16 <lambda>null17fun main() = runBlocking<Unit> { 18 val startTime = currentTimeMillis() // remember the start time 19 (1..3).asFlow().onEach { delay(100) } // a number every 100 ms 20 .flatMapLatest { requestFlow(it) } 21 .collect { value -> // collect and print 22 println("$value at ${currentTimeMillis() - startTime} ms from start") 23 } 24 } 25