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

jeggy

06/17/2020, 10:29 AM
Copy code
fun main() = runBlocking {
    repeat(50) {
        launch(<http://Dispatchers.IO|Dispatchers.IO>) {
            delay(5000L * it)
            println("Done $it")
        }
    }
}
Having some code like this. Is it possible to leak coroutines, if I were to just send the kill signal to this process?
👀 1
s

spand

06/17/2020, 10:41 AM
If you kill the process all coroutines must be gone by definition ?
☝️ 1
z

Zach Klippenstein (he/him) [MOD]

06/17/2020, 12:38 PM
You couldn't even leak threads like this, and coroutines are an entirely userspace construct.
j

jeggy

06/17/2020, 1:39 PM
Great, thanks. Just wanted to be 100% sure 😛 Cause when creating a test like this:
Copy code
@Test
fun threads() = runBlockingTest {
    (1..50).map {
        launch(<http://Dispatchers.IO|Dispatchers.IO>) {
            delay(5000L * it)
            println("Done $it")
        }
    }.joinAll()
}
The test will fail, so just wanted to be sure if that wasn't leaked anywhere. To ask a new question, what's the reason for that specific test failing?
u

uli

06/17/2020, 2:17 PM
what does it say?
j

jeggy

06/17/2020, 3:06 PM
java.lang.IllegalStateException: This job has not completed yet
t

tseisel

06/17/2020, 6:11 PM
This is a known bug of
runBlockingTest
, it seems that using another dispatcher conflicts with the auto-advancing time feature. You may reproduce the same problem with
withContext
👍 1