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.
- Create a file, say,
ScheduleActor.scala
in 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...