04/05/2020, 12:01 AM I'm curious if anyone has implemented a solution to this issue besides constructor injection of IO dispatcher?
For context, I have an abstract class that contains several methods that launch coroutines with
and switch to
inside. I would rather not constructor inject the IO Dispatcher inside every class that is implementing my abstract class, or do something like pass the IO Dispatcher as a parameter in all my public functions. Not sure if there is a way to mock this; open to suggestions! (Please!)


04/05/2020, 12:40 AM
There's indeed currently only a
to inject your own (test) dispatcher. I inject the dispatchers into my dependencies, but if you want to avoid that, you could create your own singleton in your code that uses the actual Dispatchers.Xxx per default but can be configured to return custom (test) dispatchers. This would be a bit error prone, though. Easy to forget and accidentally use the standard Dispatchers.Xxx instead....