Skip to content

Instantly share code, notes, and snippets.

@manuelvicnt
Created October 9, 2019 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelvicnt/1f351df83643a294a392257d0f1cc57f to your computer and use it in GitHub Desktop.
Save manuelvicnt/1f351df83643a294a392257d0f1cc57f to your computer and use it in GitHub Desktop.
// 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