CoroutineScope(Dispatchers.IO).launch{
print("This is before delay")
delay(1000)
print("This is after delay")
}
why does it not print after delay text
z
Zach Klippenstein (he/him) [MOD]
07/13/2021, 5:47 PM
Where are you running this? If it’s just a main function, I think the IO dispatcher’s thread pool might use daemon threads?
👍 1
v
Vikas Singh
07/14/2021, 4:54 AM
I am not using runBlocking just running in to the main function
g
gildor
07/14/2021, 8:23 AM
Coroutines are like daemon threads and use daemon threads for standard dispatchers thread pools.
Your program finished before delay is finished
You can use runBlocking or suspend main()
👍 1
gildor
07/14/2021, 8:25 AM
It also not the best way to run even top level coroutines, I would say that even GlobalSgope is better, it essentially the same, but doesn't require additional scope and more explicit