A coroutine dispatcher that is confined to the Main thread operating with UI objects. Usually such dispatcher is single-threaded.
Access to this property may throw 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 of Default dispatcher.
- On JVM it either Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by
In order to work with
Main dispatcher, following artifact should be added to project runtime dependencies:
kotlinx-coroutines-androidfor Android Main thread dispatcher
kotlinx-coroutines-javafxfor JavaFx Application thread dispatcher
kotlinx-coroutines-swingfor Swing EDT dispatcher
Implementation note: MainCoroutineDispatcher.immediate is not supported on Native and JS platforms.