Created
March 20, 2019 08:16
-
-
Save manuelvicnt/4f65fc0a7094b6aa690b59c2afb0da6b 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
class MyViewModel : ViewModel() { | |
/** | |
* Heavy operation that cannot be done in the Main Thread | |
*/ | |
fun launchDataLoad() { | |
viewModelScope.launch { | |
sortList() | |
// Modify UI | |
} | |
} | |
suspend fun sortList() = withContext(Dispatchers.Default) { | |
// Heavy work | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment