A coroutine dispatcher that is confined to the Main thread operating with UI objects. This dispatcher can be used either directly or via MainScope factory. Usually such dispatcher is single-threaded.
Access to this property may throw IllegalStateException if no main thread 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.