Created
October 9, 2019 09:03
-
-
Save manuelvicnt/1f351df83643a294a392257d0f1cc57f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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