I'm just migrating to new scoped coroutines. In one case, I'm inside a
Fragment
which implements
CoroutineScope
. The default cancellation behavior is to cancel in
onDestroy
. But one specific coroutine I want to cancel on a different event, e.g. in
onDetach
. Should I create a nested scope or should I just manually cancel the coroutine when the event happens?
k
kingsley
09/26/2018, 3:37 PM
Just manually cancelling
onDetach
sounds simple enough. Except this is a recurring behavior, I’d keep things simple 🙂
g
gildor
09/26/2018, 4:45 PM
We use own scope for both lifecycles: 1 for fragment, 1 for view.
But only if you need both, sometimes view is enough
➕ 2
k
kirillrakhman
10/02/2018, 9:09 AM
@gildor can you share the implementation for the scopes?
g
gildor
10/02/2018, 9:11 AM
As I said this is our own implementation, not based CoroutinesScope (will migrate eventually).
But it’s just 2 nested scopes, view scope canceled onDestroyView, created onViewCreated