elizarov
09/11/2017, 1:48 PMEmptyCoroutineContext
and Unconfined
are virtually the same with the exception that Unconfined
is designed to work with debugging facilities of kotlinx.coroutines
(in debug mode you’ll get the id of the executing coroutine added to the thread name — wastes a lot of CPU, but simplifies debugging)
2 replies
No. If you launch(EmptyCoroutineContext)
or launch(Unconfined)
in UI thread, then after the first async operation like delay
you’ll resume in some other thread and will not be in UI thread anymore. However, with launch(UI)
you always resume in UI thread, guaranteed. It is explained with examples in this section of the guide: https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#unconfined-vs-confined-dispatcher