Skip to content

Instantly share code, notes, and snippets.

@RBusarow
Created March 17, 2019 23:51
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/63b88afd278ca427762f18b9238a2b11 to your computer and use it in GitHub Desktop.
Save RBusarow/63b88afd278ca427762f18b9238a2b11 to your computer and use it in GitHub Desktop.
Injecting CoroutineScope into the ViewModel
class MyViewModel(
private val myRepository: MyRepository,
coroutineScope: CoroutineScope
) : BaseViewModel(coroutineScope)
abstract class BaseViewModel(
coroutineScope: CoroutineScope
) : ViewModel(), CoroutineScope by coroutineScope {
override fun onCleared() {
cancel()
super.onCleared()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment