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.

This task uses dependencies that may not be available in your local IDE. As a result, you may see compilation errors or unresolved references when running the code locally. This does not affect solution validation when you submit your solution to Hyperskill.

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