If I have access to a `CoroutineContext` via `coro...
# coroutines
s
If I have access to a
CoroutineContext
via
coroutineContext
, what is the best way for me to create child coroutines? I’m assuming I need to create a
CoroutineScope
, but there aren’t any utility methods I’ve found for this, making me think that there might be a better way?
z
To use structured concurrency, use
coroutineScope {}
. Otherwise, you can use
CoroutineScope(coroutineContext)
s
I looked at the source for
coroutineScope {}
. It doesn’t look like it uses the current scope. If I call
coroutineScope {}
inside a coroutine, will it create child coroutines?
b
Yep it takes your current context and creates child scope. coroutineScope {} suspends until all children completes
z
Yes it does, that’s pretty much its main use case.