| // This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit. |
| package guide.cancel.example04 |
| |
| import kotlinx.coroutines.experimental.* |
| |
| fun main(args: Array<String>) = runBlocking<Unit> { |
| val job = launch(CommonPool) { |
| try { |
| repeat(1000) { i -> |
| println("I'm sleeping $i ...") |
| delay(500L) |
| } |
| } finally { |
| println("I'm running finally") |
| } |
| } |
| delay(1300L) // delay a bit |
| println("main: I'm tired of waiting!") |
| job.cancel() // cancels the job |
| delay(1300L) // delay a bit to ensure it was cancelled indeed |
| println("main: Now I can quit.") |
| } |