A coroutine dispatcher that is confined to the Main thread operating with UI objects. Usually such dispatchers are single-threaded.
Access to this property may throw an IllegalStateException if no main dispatchers are present in the classpath.
Depending on platform and classpath it can be mapped to different dispatchers:
- On JS and Native it is equivalent to the Default dispatcher.
- On JVM it either the Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by the
In order to work with the
Main dispatcher, the following artifact should be added to the project runtime dependencies:
kotlinx-coroutines-android— for Android Main thread dispatcher
kotlinx-coroutines-javafx— for JavaFx Application thread dispatcher
kotlinx-coroutines-swing— for Swing EDT dispatcher
Implementation note: MainCoroutineDispatcher.immediate is not supported on the Native and JS platforms.