feroz_baig
07/26/2017, 8:10 AMfun 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?pilgr
07/26/2017, 8:11 AMferoz_baig
07/26/2017, 8:11 AM