In the same way that we used a CoroutineDispatcher to run a thread in the background, we can now use one to preform operations in the main thread.
Using a UI dispatcher
Platform-specific UI libraries
Given that there are many types of GUI applications for the JVM, Kotlin has separated some platform-specific coroutine functionality into libraries.
- kotlinx-coroutines-android
- kotlinx-coroutines-javafx
- kotlinx-coroutines-swing
Notice that all these platforms have the same UI model that we talked about before, in which only the UI thread can create and update the views. So, these tiny libraries are simply a CoroutineDispatcher that is implemented to confine coroutines to the UI thread.
The Android library also adds support for...