Created
January 30, 2021 17:26
-
-
Save GauravChaddha1996/8bb0c991a5f6565016de5c60b20a8a2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runBlocking { | |
val scope = CoroutineScope(Dispatchers.IO) | |
val j = scope.launch { | |
println("Inside parent job") | |
delay(50) | |
val p = launch { | |
println("Inside child job") | |
delay(500) | |
println("Ending of child job") | |
} | |
// Cancelling the child job after a 50ms delay | |
delay(50) | |
p.cancelAndJoin() | |
println("Ending of parent job") | |
} | |
j.join() | |
} | |
Output: | |
Inside parent job | |
Inside child job | |
Ending of parent job |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment