Created
February 12, 2019 15:34
-
-
Save wellingtoncosta/3a25bbd1f83167179cfe7f9b33c08b84 to your computer and use it in GitHub Desktop.
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
open class CoroutineViewModel : ViewModel(), CoroutineScope { | |
override val coroutineContext = Main | |
protected val jobs = ArrayList<Job>() | |
infix fun ArrayList<Job>.add(job: Job) { this.add(job) } | |
override fun onCleared() { | |
super.onCleared() | |
jobs.forEach { if(!it.isCancelled) it.cancel() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment