Dico
04/03/2019, 6:35 AMCoroutineScope
in application components that use a coroutine lifecycle, favoring an approach using private val scope = CoroutineScope(...)
That way the scope is not leaked by implementing the interface and it is in my opinion cleaner. It distinguishes better between using the scope and using the scope of a coroutine you created. What do you think? Why should we implement CoroutineScope the way it is suggested initially by structured concurrency?spand
04/03/2019, 6:46 AMaddamsson
04/03/2019, 7:08 AMinterface
should implement CoroutineScope
instead of the interface
itself?gildor
04/03/2019, 7:18 AMfavoring an approach usingBut how you cn control lifecycle of component? Just provide some method like cancel/close and delegate it to scope?private val scope = CoroutineScope(...)
gildor
04/03/2019, 7:20 AMghedeon
04/03/2019, 7:33 AMWhy should we implementWe don't have to. Check the ViewModel extension from ktx library. They (.CoroutineScope
@jw
?) did a pretty nifty trick there by going with composition, instead of inheritance.ghedeon
04/03/2019, 7:37 AMviewModelScope
extension: https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/lifecycle/viewmodel/ktx/src/main/java/androidx/lifecycle/ViewModel.kt
And here how it's being closed in ViewModel: https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/lifecycle/viewmodel/src/main/java/androidx/lifecycle/ViewModel.java
A bit hacky but I like it 🙂 It's Closeable
interface + map of tags. Could be done for Rx as well, anything that has to be cleared.Dico
04/03/2019, 9:03 PMBut how you cn control lifecycle of component? Just provide some method like cancel/close and delegate it to scope?Yeah, exactly
Dico
04/03/2019, 9:05 PMghedeon
04/03/2019, 9:32 PM