Last active
April 20, 2019 12:45
-
-
Save RBusarow/55dda437b4c64d92cb7bd363966760a1 to your computer and use it in GitHub Desktop.
Basic boilerplate version of a CoroutineScope implementation in a ViewModel, with an abstract BaseViewModel
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 : BaseViewModel() // nothing at all to implement! | |
abstract class BaseViewModel : ViewModel(), CoroutineScope { | |
private val job = SupervisorJob() | |
override val coroutineContext: CoroutineContext | |
get() = job + Dispatchers.Default | |
override fun onCleared() { | |
job.cancel() | |
super.onCleared() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment