elizarov
09/11/2017, 12:06 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)deviant
09/11/2017, 12:10 PMlaunch(EmptyCoroutineContext)
in the ui thread with same result i call launch(UI)
?deviant
09/11/2017, 1:53 PMdelay
coroutine? because i can't reproduce 'thread switching' with async(CommonPool){...}.await()
launch(Unconfined){
logThread("coroutine start")
async(CommonPool){
logThread("common pool")
}.await()
logThread("coroutine end")
}
deviant
09/11/2017, 1:53 PM16:53:27.584: coroutine start [thread:1]
16:53:27.591: common pool [thread:11]
16:53:27.595: coroutine end [thread:1]
elizarov
09/11/2017, 2:30 PMasync(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.deviant
09/11/2017, 3:15 PMThread.sleep()
inside of async
now it jumps to another thread. thanks for clarification