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

Trần Đại Nhân (Max)

03/10/2021, 3:10 AM
Hi everyone, I have some confusion with two results, the first is Kotlin JVM and the second is Android Application. Anyone can help me to explain why it a difference in results with the same code logic?
a

aleksey.tomin

03/10/2021, 3:23 AM
In JVM program stops after
main
done. You should add something after
launch
❤️ 1
t

Trần Đại Nhân (Max)

03/10/2021, 3:29 AM
Thank you for your response, your mean is this, right?
a

aleksey.tomin

03/10/2021, 3:37 AM
No. Something like
Copy code
runBlocking {
    delay(3000)
}
❤️ 1
t

Trần Đại Nhân (Max)

03/10/2021, 4:23 AM
Thank you for you help, your way can lead to race condition.
a

aleksey.tomin

03/10/2021, 4:28 AM
p

pakoito

03/10/2021, 11:48 AM
Do
suspend fun main()
instead of
GlobalScope.launch
❤️ 1
otherwise,
runBlocking { GlobalScope.launch { } }
is what you're after
❤️ 1
both are equivalent
❤️ 1
t

Trần Đại Nhân (Max)

03/10/2021, 4:29 PM
Thank for your help let me try!
6 Views