Main
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 is either the Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by the
ServiceLoader
.
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 dispatcherkotlinx-coroutines-javafx
— for JavaFx Application thread dispatcherkotlinx-coroutines-swing
— for Swing EDT dispatcher
Implementation note: MainCoroutineDispatcher.immediate is not supported on the Native and JS platforms.
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 is either Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by
ServiceLoader
.
In order to work with Main
dispatcher, the following artifacts should be added to project runtime dependencies:
kotlinx-coroutines-android
for Android Main thread dispatcherkotlinx-coroutines-javafx
for JavaFx Application thread dispatcherkotlinx-coroutines-swing
for Swing EDT dispatcher
In order to set a custom Main
dispatcher for testing purposes, add the kotlinx-coroutines-test
artifact to project test dependencies.
Implementation note: MainCoroutineDispatcher.immediate is not supported on Native and JS platforms.