Dispatchers
Learn what a dispatcher is and some of its types.
We'll cover the following...
A necessary functionality offered by the Kotlin coroutines library lets us decide which thread (or pool of threads) a coroutine should be running (starting and resuming). We’ll do this using a dispatcher.
The English dictionary defines a dispatcher as “a person responsible for sending people or vehicles to where they are needed, especially emergency vehicles.” In Kotlin coroutines, CoroutineContext
determines which thread a certain coroutine will run.
Note: Dispatchers in Kotlin Coroutines are a similar concept to RxJava Schedulers.
Default dispatcher
If we don’t set any dispatcher, the one chosen by default is Dispatchers.Default
, which is designed to run CPU-intensive operations. It has a pool of threads with a size equal to the number of cores on ...