1 // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 package kotlinx.coroutines.guide.exampleContext06
3 
4 import kotlinx.coroutines.*
5 
<lambda>null6 fun main() = runBlocking<Unit> {
7     // launch a coroutine to process some kind of incoming request
8     val request = launch {
9         // it spawns two other jobs
10         launch(Job()) {
11             println("job1: I run in my own Job and execute independently!")
12             delay(1000)
13             println("job1: I am not affected by cancellation of the request")
14         }
15         // and the other inherits the parent context
16         launch {
17             delay(100)
18             println("job2: I am a child of the request coroutine")
19             delay(1000)
20             println("job2: I will not execute this line if my parent request is cancelled")
21         }
22     }
23     delay(500)
24     request.cancel() // cancel processing of the request
25     println("main: Who has survived request cancellation?")
26     delay(1000) // delay the main thread for a second to see what happens
27 }
28