Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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