Is there a more idiomatic way to create a child sc...
# coroutines
z
Is there a more idiomatic way to create a child scope from a parent scope?
Copy code
val parentScope = CoroutineScope(Dispatchers.Default)
 val childScope = parentScope + Job(parent = scope.coroutineConext[Job]!!)
o
Copy code
parentScope.newCoroutineContext(Job(parentScope.coroutineContext[Job]))
is probably more idiomatic, and the closest I could find to what actually happens
z
My concern is that it would be easy to accidentally break structured concurrency by doing:
Copy code
val parentScope = CoroutineScope(Dispatchers.Default)
val childScope = parentScope + Job()
z
👍 1
❤️ 1
z
Yeah, I think the team picked the wrong default behavior here unfortunately. Definitely a thumbs up!
o
I mean, how would it work "right" here?
CoroutineScope(...)
is a generic, non-suspend constructor. How can it figure out what the parent Job is?