Hi. I am unable to see the print output for corout...
# getting-started
t
Hi. I am unable to see the print output for coroutines in IntelliJ Idea. For other normal kotlin code, it works fine. I have added question for details here: https://stackoverflow.com/questions/66730626/different-outputs-when-using-kotlin-playground-by-google-android-vs-intellij-w I am trying to run the code:
Copy code
import kotlinx.coroutines.*


fun main() {
    repeat(3) {
        GlobalScope.launch {
            println("Hi from ${Thread.currentThread()}")
        }
    }
}
on IntelliJ idea 2020.3.2: The output is this:
Copy code
6:14:05 PM: Executing task 'Coroutines_multipleKt.main()'...

> Task :wrapper

BUILD SUCCESSFUL in 184ms
1 actionable task: 1 executed
> Task :compileKotlin
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :Coroutines_multipleKt.main()

BUILD SUCCESSFUL in 712ms
2 actionable tasks: 2 executed
6:14:06 PM: Task execution finished 'Coroutines_multipleKt.main()'.
But on Kotlin Playground I get the output that is expected:
Copy code
Hi from Thread[DefaultDispatcher-worker-1 @coroutine#1,5,main] Hi from Thread[DefaultDispatcher-worker-1 @coroutine#2,5,main] Hi from Thread[DefaultDispatcher-worker-1 @coroutine#3,5,main]
What am I doing wrong? Why doesn't IntelliJ produce the output as desired? I have added an image:

https://i.imgur.com/N9WjEZz.png

where IntelliJ shows output, but as you can see its not producing output. Generally the blue highlighted area is where the println output would be I have added an GIF, please check:

https://i.imgur.com/1unP2hY.gif

It shows how one code works and one does not. Please guide where its going wrong
Looks like locally you need to use Thread.sleep for it to work
Copy code
fun main() {
    repeat(3) {
        GlobalScope.launch {
            println("Hi from ${Thread.currentThread()}")
        }
    }
    Thread.sleep(2000L)
}