kalpeshp0310
08/27/2019, 12:03 PMfun main() = runBlocking {
val job = launch {
repeat(1000) { i ->
println("job: I'm sleeping $i ...")
delay(500L)
}
}
delay(1300L) // delay a bit
println("main: I'm tired of waiting!")
job.cancel() // cancels the job
job.join() // waits for job's completion
println("main: Now I can quit.")
}
How does Kotlin stop execution of launch
code block?louiscad
08/27/2019, 12:05 PMCancellationException
is thrown.kalpeshp0310
08/27/2019, 12:18 PMlouiscad
08/27/2019, 12:42 PMisActive
while catching CancellationException
, but do you really need to do so?kalpeshp0310
08/27/2019, 1:02 PM