What's the difference between a Dispatcher and a S...
# coroutines
c
What's the difference between a Dispatcher and a Scheduler? I see that
<http://Dispatchers.IO|Dispatchers.IO>
is a
DefaultIoSchduler
. Are these just synonyms? Does
<http://Dispatchers.IO|Dispatchers.IO> + testScheduler
make any sense?
o
IIRC, a dispatcher is an entity that processes job queues and distributes jobs across threads. A scheduler does time keeping (for
delay
). (Just from the top of my head.)
TestCoroutineScheduler docs say
Test dispatchers are parameterized with a scheduler. Several dispatchers can share the same scheduler, in which case their knowledge about the virtual time will be synchronized. When the dispatchers require scheduling an event at a later point in time, they notify the scheduler, which will establish the order of the tasks.
But admittedly, the notion of
DefaultIoScheduler
doesn't fit into this concept. Why should IO have a different idea of time?
Seems like with
DefaultIoScheduler
(which is a
ExecutorCoroutineDispatcher
) and others, the names "dispatcher" and "scheduler" are used interchangeably. Possibly something to clean up.
Other than that, using a test scheduler with anything else than a test dispatcher doesn't seem to make sense: The test dispatcher relies on single-threading to skip time when scheduling jobs. This cannot (easily) work on a multithreaded dispatcher, which would probably not honor a separate scheduler for time keeping anyway.