Planning a feature that will run every second with Akka Scheduler

I want to run this Scala function every second:

object AuthTasker { def cleanTokens() { [...] } } 

Akka Scheduler has the following function: schedule(initialDelay: FiniteDuration, interval: FiniteDuration)(f: โ‡’ Unit)

Can I use this function to call AuthTasker.cleanToken() every second?

+6
source share
1 answer

To answer your question: Yes, you can call AuthTasker.cleanToken () every second using the schedule method. I recommend the following (including import 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 second, not every 0 seconds. I caught an error while paying attention to the code.

+12
source

Source: https://habr.com/ru/post/957794/


All Articles