Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Bad practice
class MyViewModel() {
fun example() {
// ------------------ code smell ---------
viewModelScope.launch(Dispatchers.IO) { … }
}
}
// Inject Dispatchers as shown below!
class MyViewModel(private val ioDispatcher: CoroutineDispatcher): ViewModel() {
fun example() {
// ------------------ good practice -----
viewModelScope.launch(ioDispatcher) { … }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.