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

tmg

05/14/2020, 10:23 AM
Hi guys, QQ: I’ve this
Copy code
class Foo {
   suspending fun foo() { /* some code */ }
And inside it I would like to launch some child coroutines (and await their ending, so, like
coroutineScope {}
), what’s the correct pattern for it? I’ve seen people using
class Foo : CoroutineScope
to be able use use launch or coroutineScope directly, but what does this actually do?
a

araqnid

05/14/2020, 11:28 AM
You can run
coroutineScope
within any suspending function, no need to have a CoroutineScope receiver- it will create a new Job with a parent from the current context’s Job
❤️ 1
Having a CoroutineScope receiver just allows
launch
etc to be able to access a context when run from a non-suspending function- the CoroutineScope interface is basically just a
coroutineContext
property
t

tmg

05/14/2020, 11:47 AM
You can run 
coroutineScope
 within any suspending function
didn’t notice that 🤦 thanks!
2 Views