<https://kotlinlang.org/api/kotlinx.coroutines/kot...
# coroutines
c
https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/ mentions the possibility to create multiple
StandardTestDispatcher
in a single test. Why would you want to do this?
s
In the example in the docs, it seems like the only real reason is to give the two dispatchers different names, for debugging purposes
I guess I can also imagine a scenario where the code under test has some logic like
Copy code
if (currentDispatcher == dispatcher1) {
  doOneThing()
} else {
  doSomeOtherThing()
}
So the identity of the dispatcher might sometimes be important
c
Where is the event loop implemented? Will that allow both dispatchers to start tasks in parallel? (AFAIK
runTest
is single-threaded?)
s
The dispatcher is mostly just a wrapper around the
TestCoroutineScheduler
, which is what contains the event loop. The
runTest
function just grabs the scheduler from the
TestScope
and runs its event loop.
So you wouldn't be able to use two different schedulers, unless you were manually advancing the event loop somehow. As far as I understand it, the scheduler has to be wired up to the
runTest
function for it to actually start running anything.
c
Ah, I see. I always confuse schedulers and dispatchers
s
I think the distinction is only really made for test dispatchers. Elsewhere in the coroutines library, dispatcher and scheduler seem to be mostly synonymous.