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

Slackbot

11/08/2018, 6:09 PM
This message was deleted.
l

louiscad

11/08/2018, 6:17 PM
A scope has a context
c

chi

11/08/2018, 6:21 PM
Yeah, but why do we need to define a scope and a context, I'm trying to make a clear distinction about why each is important and what it's actual role is
l

louiscad

11/08/2018, 6:23 PM
A
CoroutineScope
is there to provide a default
CoroutineContext
to use for coroutine builders like
launch
. Also, a scope makes concurrency structured, making leaks harder to do.
f

Felix

11/08/2018, 6:55 PM
Scope: every coroutine needs to be created on a scope. A cancellation or unhandled exception on a coroutine influences other coroutines in the same scope. It is also possible to synchronise with the completion of all coroutines on a scope. Context: is an immutable set of context elements that is always accessible by a coroutine (even if hosted on different threads) during its lifetime (similar to Thread Local Storage for "classical" threads). Some of this context elements also control some of the coroutine behaviour, namely thread dispatching. Makes sense?
👍 2
m

mayojava

11/08/2018, 9:58 PM
All coroutine builders are launched within a particular scope. The scope itself wraps a context that holds things like the coroutine name, dispatcher, uncaught exception handler and job
3 Views