Patrick Steiger
03/31/2023, 12:47 PMyield() to run pending coroutines does not seem to work on Kotlin Playground, wonder why is thatjw
03/31/2023, 12:50 PMPatrick Steiger
03/31/2023, 12:55 PMPatrick Steiger
03/31/2023, 12:58 PMPatrick Steiger
03/31/2023, 1:03 PMjw
03/31/2023, 1:04 PMjw
03/31/2023, 1:04 PMjw
03/31/2023, 1:04 PMDmitry Khalanskiy [JB]
03/31/2023, 1:05 PMDispatchers.Default is a multi-threaded dispatcher, so yield just means "relinquish the thread." However, the coroutine launch-ed is likely going to use a different thread. So, what happens here is a race: if, after the yield, the cancel manages to finish before the coroutine actually starts, the coroutine will not be run. So, there are no guarantees one way or another for whether yield helps here.Dmitry Khalanskiy [JB]
03/31/2023, 1:07 PMPatrick Steiger
03/31/2023, 1:07 PMnewSingleThreadContext(“single thread”) on playground eliminates the race it seemsDmitry Khalanskiy [JB]
03/31/2023, 1:08 PMwithContext coroutine does not relinquish its thread at all, but with enough time, another thread is provisioned.Patrick Steiger
03/31/2023, 1:11 PMyield will always run the pending coroutine with no risk of races ?Dmitry Khalanskiy [JB]
03/31/2023, 1:13 PMPatrick Steiger
03/31/2023, 1:13 PM