Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created April 11, 2020 10:17
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 magdamiu/a789004a0c0202a0860c05d7af70c966 to your computer and use it in GitHub Desktop.
Save magdamiu/a789004a0c0202a0860c05d7af70c966 to your computer and use it in GitHub Desktop.
Cancellation using cancel() and join()
import kotlinx.coroutines.*
fun main() {
runBlocking {
println("Start main")
val job = launch {
repeat(300) { waitingTime ->
println("Job is waiting $waitingTime...")
delay(50L)
}
}
delay(300L)
println("Stop waiting. Let's cancel it...")
job.cancel()
job.join()
println("End main")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment