Last active
April 20, 2019 12:45
-
-
Save RBusarow/a02af06bb644e182be11b696dc54757e to your computer and use it in GitHub Desktop.
Basic boilerplate version of a CoroutineScope implementation in a ViewModel
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 { | |
private val job = SupervisorJob() | |
override val coroutineContext: CoroutineContext | |
get() = SupervisorJob() + 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