Dispatching twice

Report a typo

You have a code that does a networking operation, and now we need to process it. The networking takes a lot of time, and its processing uses a lot of CPU. Your task is to make sure the flow runs in a dedicated IO dispatcher's context, the processing happens in the Computation dispatcher context, but the result is still collected in the main thread.

A `.flowOn` operator can be used multiple times in a long flow chain

Sample Input 1:

Sample Output 1:

IO Started
CPU Processed Value
main Collected Value
Write a program in Kotlin
fun main() = runBlocking {
// dispatchers are pre-defined for you
val ioDispatcher = predefinedNetworkOperationsDispatcher
val cpuDispatcher = predefinedOneCpuDispatcher
// add operators where necessary without changing existing ones
longFlow()
.map { data -> process(data) }
.collect { data -> log("Collected $data")}
}
___

Create a free account to access the full topic