hi, if I'm given a `scope` called `bigScope` how ...
# coroutines
m
hi, if I'm given a
scope
called
bigScope
how can I create a scope
smallScope
that will be canceled when
bigScope
is cancelled?
o
CoroutineScope(Job(bigScope.coroutineContext[Job]))
?
m
Copy code
val smallScope = CoroutineScope(Dispatchers.Main + bigScope.coroutineContext)
like that?
is Job necessary?
Copy code
val smallScope = CoroutineScope(Dispatchers.Main + Job(bigScope.coroutineContext[Job]))
compiles too, could you point a difference?
o
yes, the
Job(parent: Job)
constructor means structured concurrency
basically it declares that
smallScope
is a child of
bigScope
rather than the same Job as
bigScope
m
great, thankyou 🙂