1

I am writing desktop app using Kotlin and I want to repeat execution of function for every X seconds.

I found solutions with using android library, there is other option? Maybe something like TaskRunner in Java?

SOLUTION

I used Timer().schedule(startAfter, delay){...} easy and simple ;)

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
ACz
  • 567
  • 5
  • 22

1 Answers1

0

You can use the timer function from kotlin-stdlib

Example of usage:

fun main(args: Array<String>)  {
    val timer = timer(period = 1000) { // period in milliseconds
        println("this task is repeating 10 times")
    }
    Thread.sleep(10000)
    timer.cancel()
    timer.purge()
}
Lionel Briand
  • 1,732
  • 2
  • 13
  • 21