You are currently viewing Different outputs when using Kotlin playground (by Google Android) vs IntelliJ

Different outputs when using Kotlin playground (by Google Android) vs IntelliJ

I am trying to run this code:

“` import kotlinx.coroutines.*

fun main() { repeat(3) { GlobalScope.launch { println(“Hi from ${Thread.currentThread()}”) } } }

“`

In IntelliJ I get this output:

“` 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:

“` 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]

“`

IntelliJ version: 2020.3.2

Kotlin Playground: https://developer.android.com/training/kotlinplayground

What am I doing wrong?

Why doesn’t IntelliJ produce the output as desired?

submitted by /u/Kaori_iu
[link] [comments]