Created
February 5, 2020 15:05
-
-
Save Nublo/367a658a4d2e00fd33a6b08c8ee7ccae to your computer and use it in GitHub Desktop.
This file contains 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
val startTime = System.currentTimeMillis() | |
val job = launch (Dispatchers.Default) { | |
var nextPrintTime = startTime | |
var i = 0 | |
while (i < 5) { | |
if (System.currentTimeMillis() >= nextPrintTime) { | |
println("Hello ${i++}") | |
nextPrintTime += 500L | |
} | |
} | |
} | |
delay(1000L) | |
println("Cancel") | |
job.cancel() | |
println("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment