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

sitepodmatt

02/14/2019, 4:24 AM
Other than the obvious of passing it in as a parameter?
g

gildor

02/14/2019, 4:34 AM
It also may be extension function of CorroutineScope (same as launch/async), but it depends on your use case
s

sitepodmatt

02/14/2019, 5:00 AM
but a suspend function doesn't have access to the existing CoroutineScope (caller's) unless it's passed in?
g

gildor

02/14/2019, 5:18 AM
yes
There are ways to implicitly connect to scope lifecycle (get Job from coroutineContext and set it as parent job) and just use GlobalScope
But it’s more about your use case and semantics
Most obvious and flexible way: pass CoroutineScope as parameter to function, so this function can start new coroute (background one!) that explicitly connected to lifecycle of passed scope
3 Views