Skip to content

Files

Latest commit

 

History

History
30 lines (20 loc) · 720 Bytes

InjectDispatcher.md

File metadata and controls

30 lines (20 loc) · 720 Bytes

Pattern: Use of hardcoded Dispatchers

Issue: -

Description

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)

Further Reading