# Intellij idea does not show coroutine results but Kotlin Playgroun does

**URL:** <https://discuss.kotlinlang.org/t/intellij-idea-does-not-show-coroutine-results-but-kotlin-playgroun-does/26715>\
**Category:** Support\
**Created:** [April 21, 2023, 12:30am UTC](https://discuss.kotlinlang.org/t/intellij-idea-does-not-show-coroutine-results-but-kotlin-playgroun-does/26715 "2023-04-21T00:30:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bt\_nam](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bt\_nam](https://discuss.kotlinlang.org/u/bt_nam)\
**Post date:** [April 21, 2023, 12:30am UTC](https://discuss.kotlinlang.org/t/intellij-idea-does-not-show-coroutine-results-but-kotlin-playgroun-does/26715/1 "2023-04-21T00:30:41Z")

</div>

```auto
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlin.random.Random

fun randomSharedFlow(): Flow<Int> {
    val sharedFlow = MutableSharedFlow<Int>()
    GlobalScope.launch(Dispatchers.Default) {
        for (i in 0 until 10) {
            sharedFlow.emit(Random.nextInt(1,100))
            delay(200)
        }
    }
    return sharedFlow
}

fun main() {
    val sharedFlow = randomSharedFlow()
    GlobalScope.launch(Dispatchers.Default) {
        sharedFlow.collect { println("Collector A: $it") }
        println("That's all folks!")
    }
    GlobalScope.launch(Dispatchers.Default) {
        sharedFlow.collect { println("Collector B: $it") }
        println("That's all folks!")
    }
    println("...and we're off!")
}

```

If this code is run in Intellij Idea, the result is only: …and we’re off!"  
If it is run on kotlin Playground: I did receive some values like this: Collector B: 22 Collector A: 22 Collector B: 52 .  
Also, why isn’t “That’s all folks!” printed?  
Thank you for reading.

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [April 21, 2023, 7:32am UTC](https://discuss.kotlinlang.org/t/intellij-idea-does-not-show-coroutine-results-but-kotlin-playgroun-does/26715/2 "2023-04-21T07:32:59Z")

</div>

Coroutines running in the background don’t keep the process alive. The application finishes before these coroutines have a chance to do anything. Maybe Playground is configured differently.

If you want to wait on something, then you should not use `GlobalScope.launch()` which by design doesn’t care about the result. Use `runBlocking()` and inside it `launch()` or something similar.

---

<div class="post-metadata">

**Author:** ![bt\_nam](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bt\_nam](https://discuss.kotlinlang.org/u/bt_nam)\
**Post date:** [April 21, 2023, 8:57am UTC](https://discuss.kotlinlang.org/t/intellij-idea-does-not-show-coroutine-results-but-kotlin-playgroun-does/26715/3 "2023-04-21T08:57:27Z")

</div>

Thank you very much for your help.
