I want to run this Scala function every second:
object AuthTasker {
def cleanTokens() {
[...]
}
}
Akka's Scheduler has the following function: schedule(initialDelay: FiniteDuration, interval: FiniteDuration)(f: ⇒ Unit)
Can I use that function in order to call AuthTasker.cleanToken()
every second?
To answer your question: Yes, you can call AuthTasker.cleanToken() every second with the schedule method. I recommend the following (included the imports for you):
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import ExecutionContext.Implicits.global
val system = akka.actor.ActorSystem("system")
system.scheduler.schedule(0 seconds, 1 seconds)(AuthTasker.cleanTokens)
Note: This updated code calls the scheduled method every one second rather than every 0 seconds. I caught the mistake when looking back at the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With