https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

dave08

10/16/2018, 3:15 AM
What about using
class MainPresenter : CoroutineScope by CoroutineScope(Dispatchers.Main)
to get rid of a bit of boilerplate, just missing an easy way to access its Job to cancel it on the end of its lifecycle...?
g

gildor

10/16/2018, 3:15 AM
you can easily access job using
coroutineContext
you can even just call
coroutineContext.cancel()
d

dave08

10/16/2018, 3:18 AM
Good idea, thanks! I guess anyways it'll only have one Job instance there... I thought cancel was only on Job. Doesn't make sense to cancel other contexts, does it?
g

gildor

10/16/2018, 3:58 AM
Yes, one Job instance, so this will not work for things that has complicated lifecycle. like fragments
2 Views