Joan Colmenero
03/09/2020, 5:12 PMZach Klippenstein (he/him) [MOD]
03/09/2020, 5:15 PMEmptyCoroutineContext is a CoroutineContext that doesn’t have any elements. It’s an “identity” value for addition (EmptyCoroutineContext + someOtherContext == someOtherContext).
It’s useful as a default value for context parameters.Zach Klippenstein (he/him) [MOD]
03/09/2020, 5:18 PMContinuationInterceptor is something that can wrap every Continuation generated by the language within a particular CoroutineContext. It is how CoroutineDispatcher is implemented: whenever a Continuation is generated, CoroutineDispatcher wraps that continuation one that will “post” the original continuation on the correct thread pool.
It’s a pretty low-level tool, probably not something you ever need to implement directly.zak.taccardi
03/09/2020, 5:44 PMEmptyCoroutineContext over Dispatchers.Unconfined?Zach Klippenstein (he/him) [MOD]
03/09/2020, 5:49 PMEmptyCoroutineContext, that means no dispatcher is specified, so when launching a new coroutine, the runtime will pick the default dispatcher (Dispatchers.Default).
If the context contains Dispatchers.Unconfined, then it’s the same as specifying any other dispatcher in the context – new coroutines will use that dispatcher.
When adding to another context, EmptyCoroutineContext has no effect whereas Dispatchers.Unconfined will override the dispatcher:
(myContext + EmptyCoroutineContext)[ContinuationInterceptor] == myContext[ContinuationInterceptor]
(myContext + Dispatchers.Unconfined)[ContinuationInterceptor] == Dispatchers.Unconfinedzak.taccardi
03/09/2020, 5:53 PMDispatchers.Unconfined?zak.taccardi
03/09/2020, 5:53 PMzak.taccardi
03/09/2020, 5:54 PMCoroutineScope from runBlocking { } or runBlockingTest { }zak.taccardi
03/09/2020, 5:54 PMZach Klippenstein (he/him) [MOD]
03/09/2020, 5:56 PMUnconfined for “wiring” coroutines – coroutines that just shuffle data between other communication mechanisms – because it doesn’t make sense to waste time hopping around threads just to make thread-safe calls.Joan Colmenero
03/09/2020, 6:51 PMZach Klippenstein (he/him) [MOD]
03/09/2020, 6:52 PMIt’s useful as a default value for context parameters.`ContinuationInterceptor`:
It’s a pretty low-level tool, probably not something you ever need to implement directly.