I want to call an arbitrary function every n seconds. Basically I want something identical to SetInterval from Javascript. How can I achieve this i
If you happen to be on Akka, Scheduler is quite convenient for this:
val system = ActorSystem("mySystem", config)
// ...now with system in current scope:
import system.dispatcher
system.scheduler.schedule(10 seconds, 1 seconds) {
doSomeWork()
}
There is also scheduleOnce for one-off execution.
The usual warnings about closing over mutable state apply.