Created
January 30, 2021 18:10
-
-
Save GauravChaddha1996/064382d03905e4e52c71cb1f8a070559 to your computer and use it in GitHub Desktop.
This file contains 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(), 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