Last active
May 2, 2021 21:19
-
-
Save rashanjyot/13e2069f6181190c413a90627a6b1697 to your computer and use it in GitHub Desktop.
Structured concurrency - example1
This file contains 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
val parentJob = launch { | |
val childJob = launch { | |
var count = 1 | |
while (count <= 5) { | |
println("Count: $count") | |
delay(100) | |
count++ | |
} | |
} | |
} | |
delay(250) | |
println("Cancelling parent job") | |
parentJob.cancel() | |
----------- | |
OUTPUT: | |
Count: 1 | |
Count: 2 | |
Count: 3 | |
Cancelling parent job |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment