Last active
April 20, 2019 13:14
-
-
Save RBusarow/3d4d8b4698afe4a6a26359db03964cab to your computer and use it in GitHub Desktop.
CoroutineScope class delegation
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
abstract class BaseViewModel : | |
ViewModel(), | |
CoroutineScope by SupervisorCoroutineScope(Dispatchers.Default) { | |
override fun onCleared() { | |
cancel() | |
super.onCleared() | |
} | |
} | |
abstract class BaseActivity : | |
Activity(), | |
CoroutineScope by MainScope() { | |
override fun onDestroy() { | |
cancel() | |
super.onDestroy() | |
} | |
} | |
// this is dangerous since the class doesn't have a lifecycle! | |
class MyRepositoryImpl : | |
MyRepository, | |
CoroutineScope by SupervisorCoroutineScope(Dispatchers.IO) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment