I have come across some code that creates a CoroutineScope
with a single thread context
val serialThreadContext = newSingleThreadContext("mysinglethreadcontext")
fun myScope(): CoroutineScope = CoroutineScope(serialThreadContext)
Then elsewhere in the code base, coroutines are launched in this scope...
myScope().launch {
someOtherMethod()
...
}
From what I understand, all of these created coroutines will be scheduled on the same thread, but I can't find any specific documentation on order of execution or suspension.
This raises the following questions in my mind:
if
someOtherMethod
doesn't contain anysuspend
functions, can this coroutine still be suspended by the thread?is there any guaranteed order of execution when the thread pulls the coroutine from the scheduler?