https://kotlinlang.org logo
#announcements
Title
# announcements
f

feroz_baig

07/26/2017, 8:10 AM
Copy code
fun main(args: Array<String>) = runBlocking {
            val job = launch(CommonPool) {
                var nextPrintTime = System.currentTimeMillis()
                var i = 0
                while (i < 10) { // computation loop
                    val currentTime = System.currentTimeMillis()
                    if (currentTime >= nextPrintTime) {
                        println("I'm sleeping ${i++} ...")
                        nextPrintTime += 500L
                    }
                }
            }
            delay(1300L) // delay a bit
            println("main: I'm tired of waiting!")
            job.cancel() // cancels the job
            delay(1300L) // delay a bit to see if it was cancelled....
            println("main: Now I can quit.")
            }
Why is the job not cancelled after calling it explicitly?
p

pilgr

07/26/2017, 8:11 AM
send this to #coroutines please
f

feroz_baig

07/26/2017, 8:11 AM
Sure
2 Views