MainCoroutineDispatcher

abstract class MainCoroutineDispatcher : CoroutineDispatcher

Base class for special CoroutineDispatcher which is confined to application "Main" or "UI" thread and used for any UI-based activities. Instance of MainDispatcher can be obtained by Dispatchers.Main.

Platform may or may not provide instance of MainDispatcher, see documentation to Dispatchers.Main

Constructors

MainCoroutineDispatcher
Link copied to clipboard
fun MainCoroutineDispatcher()

Functions

limitedParallelism
Link copied to clipboard
open override fun limitedParallelism(parallelism: Int): CoroutineDispatcher

Creates a view of the current dispatcher that limits the parallelism to the given value. The resulting view uses the original dispatcher for execution, but with the guarantee that no more than parallelism coroutines are executed at the same time.

toString
Link copied to clipboard
open override fun toString(): String

Returns a name of this main dispatcher for debugging purposes. This implementation returns Dispatchers.Main or Dispatchers.Main.immediate if it is the same as the corresponding reference in Dispatchers or a short class-name representation with address otherwise.

Properties

immediate
Link copied to clipboard
abstract val immediate: MainCoroutineDispatcher

Returns dispatcher that executes coroutines immediately when it is already in the right context (e.g. current looper is the same as this handler's looper) without an additional re-dispatch.

Sources

common source
Link copied to clipboard