Skip to content

Instantly share code, notes, and snippets.

@RBusarow
Last active April 20, 2019 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RBusarow/a02af06bb644e182be11b696dc54757e to your computer and use it in GitHub Desktop.
Save RBusarow/a02af06bb644e182be11b696dc54757e to your computer and use it in GitHub Desktop.
Basic boilerplate version of a CoroutineScope implementation in a ViewModel
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