Is it normal that coroutine takes almost 50ms to r...
# coroutines
m
Is it normal that coroutine takes almost 50ms to run the code in the
launch
block? No context switching, same thread. Simple
MainScope().launch {}
. Is there a way to run it sequentially or at least with smaller delays?
s
Copy code
printTime() // 0 secs passed
launch {
  printTime() // 5 secs passed
}
sleep(5)
if you don’t do context switching and, as you said, same thread, it is okay for coroutine to move your code block to the end of the block stack, so it won’t run, until previous block is finished
m
ooh, that makes sense, thanks!
l
If thats on Android then launching a coroutine on the main thread is like posting a runnable to the message queue of the main thread and this can take some time if it is able to process your runnable. I think there is
Dispatchers.Main.immediate
that executes your launched coroutine immediately.
👍 2
m
awesome, that's what I was looking for, thanks!