I'm reading this, but admittedly more confused tha...
# coroutines
c
I'm reading this, but admittedly more confused than ever about scope and context, etc https://elizarov.medium.com/coroutine-context-and-scope-c8b255d59055 Anyone have any favorite articles that made it click for them?
a
A way I think about it which might be useful: If I see a
CoroutineScope
, I expect that it is a fully formed and valid scope that I can launch things into, and pass around as a scope, and is generally participating in structured concurrency. If I see a
CoroutineContext
, it could be entirely empty, or just contain one thing (like a dispatcher) that I am collecting together in order to eventually create a new, fully formed
CoroutineScope
later It's very roughly like a
CoroutineContext
is a
Builder
of stuff related to coroutines, and then eventually it gets built into a
CoroutineScope
. If you have a normal
Builder
for something, it'd be strange to do anything to the in-progress builder except continuing to make tweaks - It's only once you call
.build()
that you'd actually want to do things on the data type since now you have a "fully formed" object.
c
thonk
p
I think of
CoroutineScope
as a
CoroutineContext
that, by convention, has a
Job
, and as such is able to launch new coroutines constrained by structured concurrency. It’s a specialization of the
CoroutineContext
with a different name and purpose