<@U0BNGCVCK> `EmptyCoroutineContext` and `Unconfin...
# coroutines
e
@deviant
EmptyCoroutineContext
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)
d
thanks, Roman. do i understand correct that i can use
launch(EmptyCoroutineContext)
in the ui thread with same result i call
launch(UI)
?
is it valid only for
delay
coroutine? because i can't reproduce 'thread switching' with
async(CommonPool){...}.await()
Copy code
launch(Unconfined){
        logThread("coroutine start")
        async(CommonPool){
            logThread("common pool")
        }.await()
        logThread("coroutine end")

    }
Copy code
16:53:27.584: coroutine start [thread:1]
16:53:27.591: common pool [thread:11]
16:53:27.595: coroutine end [thread:1]
e
It is true with any suspending function. In your example, I think, the
async(CommonPool)
coroutine just finishes too fast, so that
await
does not suspend and stays in the same thread. Just spin there for while to see how
Unconfined
coroutine can jump threads.
👍 1
d
wow. with
Thread.sleep()
inside of
async
now it jumps to another thread. thanks for clarification