Load data in IO pool

Report a typo

We have an API for loading data from a server, and our app needs to wait for complete loading. However, since we may need a graphical UI, we can't do the loading in the main thread, as that may hang the window. Thus, we need to suspend and move the loading to the IO Dispatcher.

Your task is to execute the loadData() function so that the app doesn't quit before it's done and all the loading happens in the IO thread.

Write a program in Kotlin
fun main() = runBlocking(Dispatchers.Default) {
println("Started in " + coroutineContext[CoroutineDispatcher])

// `loadData()` function is already defined for you
// make it run in an appropriate thread pool here
// don't modify the prints

println("Finished in " + coroutineContext[CoroutineDispatcher])
}
___

Create a free account to access the full topic