Last active
February 12, 2019 14:10
-
-
Save PhilippeBoisney/3da4e7c0262123d0cc4ed38db71d3c85 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
abstract class BaseViewModel: ViewModel() { | |
/** | |
* This is a scope for all coroutines launched by [BaseViewModel] | |
* that will be dispatched in a Pool of Thread | |
*/ | |
protected val ioScope = CoroutineScope(Dispatchers.Default) | |
/** | |
* Cancel all coroutines when the ViewModel is cleared | |
*/ | |
override fun onCleared() { | |
super.onCleared() | |
ioScope.coroutineContext.cancel() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment