Skip to content

Instantly share code, notes, and snippets.

@rashanjyot
Last active May 2, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashanjyot/13e2069f6181190c413a90627a6b1697 to your computer and use it in GitHub Desktop.
Save rashanjyot/13e2069f6181190c413a90627a6b1697 to your computer and use it in GitHub Desktop.
Structured concurrency - example1
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