https://kotlinlang.org logo
#coroutines
Title
# coroutines
v

voddan

05/08/2018, 3:52 PM
Hi! If I have a
newSingleThreadedCoroutrineContext
, and a bunch of coroutine launched with it, a) will the coroutines execute in the order of their creation? b) will the execution prefer the first coroutine more than the last after some suspends and resumes?
v

Vsevolod Tolstopyatov [JB]

05/08/2018, 3:57 PM
Hi, a) In order of their dispatching, not creation. E.g. consider
CoroutineStart.Lazy
b) Which coroutine is the first and which one is the last? In general
newSingleThread
(and
newThreadPoolContext
) are backed by
java.util.concurrent.ThreadPoolExecutor
, so if coroutine
A
was dispatched before coroutine
B
, then it will start its execution before
B
, following original executor FIFO policy
2 Views