Robert von Massow
09/07/2020, 9:34 AMrunBlocking {
val coroutineScope = CoroutineScope(EmptyCoroutineContext)
val flowScope = CoroutineScope(EmptyCoroutineContext)
flowScope.launch {
val flow = flowOf(1)
while (isActive)
flow.collect { i ->
println("received $i")
coroutineScope.launch {
// Offload some hard work
println("processing $i")
Thread.sleep(1000)
println("done processing $i")
}
}
}
// just added so it doesn't terminate right away
delay(10000)
}
Zach Klippenstein (he/him) [MOD]
09/07/2020, 7:45 PMRobert von Massow
09/08/2020, 7:09 AMZach Klippenstein (he/him) [MOD]
09/08/2020, 8:02 AMRobert von Massow
09/08/2020, 8:03 AMZach Klippenstein (he/him) [MOD]
09/08/2020, 8:25 AMRobert von Massow
09/08/2020, 9:11 AM