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

nwh

11/03/2018, 12:13 AM
Within a body of a
suspend
function, shouldn't the current
CoroutineScope
be accessible? Since it had to be invoked from some type of scope?
l

louiscad

11/03/2018, 12:21 AM
@nwh It's recommended to make a child scope, with
coroutineScope { … }
. Does this fit your use case?
n

nwh

11/03/2018, 12:27 AM
I suppose. Honestly, I think I'm getting confused here. Isn't a
CoroutineScope
basically just a fancy
Job
with a bundled context for convenience?
l

louiscad

11/03/2018, 1:07 AM
You can see it this way, but the
Job
is actually part of the
coroutineContext
that the scope provides
m

Mark

11/03/2018, 3:15 AM
Is it correct to say: the
coroutineContext
provided by the
coroutineScope{}
is the same as the
coroutineContext
used to call the suspending function, and the
Job
is a child of the
Job
representing the call the suspending function?
l

louiscad

11/03/2018, 7:32 AM
It's not exactly the same as its job is not the same, but a child one
👍 1
d

Dico

11/03/2018, 12:57 PM
I once wondered why they didn't just use
CoroutineContext
in the place of
CoroutineScope
. But it makes sense, you can't just add scopes together and stuff.
n

nwh

11/04/2018, 1:30 AM
I'm still struggling with the difference between
CoroutineContext
and
CoroutineScope
- I get the technical difference, but not in practice
m

Mark

11/04/2018, 2:19 AM
Same here. It’s the conceptual difference that is not clear to me.
d

DALDEI

11/04/2018, 5:16 AM
My take on this (after being totally lost for a while) is the introduction of a new term 'Scope' which implies very much like DSL contextual 'Scope.' A CoroutineScope is a "DSL LIke" container which injects a coroutine context into the calling textual scope much like say let {} or with {}
This then lets all sorts of magic happen by adding properties to the scope which append, ammend or override parent properties of the same name.
2 Views