Skip to content

Instantly share code, notes, and snippets.

@mayojava
Created October 26, 2018 10:17
Show Gist options
  • Save mayojava/9b9a688ec0e12f8e9e638615de853841 to your computer and use it in GitHub Desktop.
Save mayojava/9b9a688ec0e12f8e9e638615de853841 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) = runBlocking<Unit> {
val job = launch {
repeat(10) {
println("hello")
delay(500)
}
}
delay(2000) // delays for launched coroutine to run for a while
println("cancelling")
job.cancel()
}
//console output
hello
hello
hello
hello
cancelling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment