Skip to content

Instantly share code, notes, and snippets.

@Nublo
Created February 5, 2020 15:05
Show Gist options
  • Save Nublo/367a658a4d2e00fd33a6b08c8ee7ccae to your computer and use it in GitHub Desktop.
Save Nublo/367a658a4d2e00fd33a6b08c8ee7ccae to your computer and use it in GitHub Desktop.
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