1 /* 2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit. 6 package kotlinx.coroutines.guide.exampleContext06 7 8 import kotlinx.coroutines.* 9 <lambda>null10fun main() = runBlocking<Unit> { 11 // launch a coroutine to process some kind of incoming request 12 val request = launch { 13 // it spawns two other jobs, one with GlobalScope 14 GlobalScope.launch { 15 println("job1: I run in GlobalScope and execute independently!") 16 delay(1000) 17 println("job1: I am not affected by cancellation of the request") 18 } 19 // and the other inherits the parent context 20 launch { 21 delay(100) 22 println("job2: I am a child of the request coroutine") 23 delay(1000) 24 println("job2: I will not execute this line if my parent request is cancelled") 25 } 26 } 27 delay(500) 28 request.cancel() // cancel processing of the request 29 delay(1000) // delay a second to see what happens 30 println("main: Who has survived request cancellation?") 31 } 32