Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MyViewModel : ViewModel(), CoroutineScope {
override val coroutineContext =
viewModelScope.coroutineContext + Dispatchers.Default
fun someF() {
launch {
// No need to write viewModelScope.launch
// and this is automatically on Dispatchers.Default
}
}
// Since our scope uses the context from viewModelScope when it is cancelled,
// so is our custom scope and hence all
// coroutines launched inside our custom scope
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment