xref: /aosp_15_r20/external/kotlinx.coroutines/kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt (revision 7a7160fed73afa6648ef8aa100d4a336fe921d9a)

<lambda>null1 // This file was automatically generated from cancellation-and-timeouts.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleCancel01
3 
4 import kotlinx.coroutines.*
5 
6 fun main() = runBlocking {
7     val job = launch {
8         repeat(1000) { i ->
9             println("job: I'm sleeping $i ...")
10             delay(500L)
11         }
12     }
13     delay(1300L) // delay a bit
14     println("main: I'm tired of waiting!")
15     job.cancel() // cancels the job
16     job.join() // waits for job's completion
17     println("main: Now I can quit.")
18 }
19