Created
October 26, 2018 10:17
-
-
Save mayojava/9b9a688ec0e12f8e9e638615de853841 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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