Scheduling an actor's operation at a specified interval
Scheduling an actor is the same as we scheduling the simple operation. There are cases where we want an actor to do some after some work repeatedly after an interval of time.Â
Getting ready
Just import the Hello-Akka project in the IDE; no other prerequisites are required.Â
How to do it…
- Create a file, say,
ScheduleActor.scalain thecom.packt.chapter5Â package. - Add the following imports to the top of the file:
       import akka.actor.{Actor, Props, ActorSystem}
       import scala.concurrent.duration._- Create a simple actor, as follows, that adds two random integers:
       class RandomIntAdder extends Actor {
       val r = scala.util.Random
       def receive = {
       case "tick" =>
       val randomInta = r.nextInt(10)
       val randomIntb = r.nextInt(10)
       println(s"sum of $randomInta and $randomIntb is
${randomInta + randomIntb}")
       }
       }- Create a test application...