Pattern: Use of hardcoded Dispatchers
Issue: -
Always use dependency injection to inject dispatchers for easier testing.
Example of incorrect code:
fun myFunc() {
coroutineScope(Dispatchers.IO)
}
Example of correct code:
fun myFunc(dispatcher: CoroutineDispatcher = Dispatchers.IO) {
coroutineScope(dispatcher)
}
class MyRepository(dispatchers: CoroutineDispatcher = Dispatchers.IO)