Dispatching once

Report a typo

You have a code that does a very long networking operation. Your task is to make sure it's executed in the context of a dedicated IO dispatcher but is still collected in the main thread.

Write a program in Kotlin
fun main() = runBlocking {
// dispatcher is pre-defined for you
val ioDispatcher = predefinedNetworkOperationsDispatcher
// add operators where necessary without changing existing ones
longFlow()
.map { data -> log("Processed $data"); data }
.collect { data -> log("Collected $data")}
}
___

Create a free account to access the full topic