Solution: Practice a Suspending Function Using Flow
See the solution to the challenge you just solved.
We'll cover the following...
Solution
The solution to the challenge is as follows.
fun getFlow(): Flow<String> = flow { repeat(3) { delay(1000) emit("User$it") } } suspend fun main() { withContext(newSingleThreadContext("main")) { launch { repeat(3) { delay(100) println("Processing on coroutine") } } val list = getFlow() list.collect { println(it) } } }
Solution to the challenge
Here is a line–by–line ...