The earlier snippet showed how a nonactor code used the asked pattern. The upcoming snippet shows how an actor asks another for some service.
We have two actors. Actor1 receives an Actor2 reference in its constructor. When Actor1 receives a string message, it delegates the message to Actor2.
The Actor2 message processing simulates a delay of one second and then upcases the argument string and returns it back as shown in the following:
package com.concurrency.book.chapter08import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props}import akka.pattern.askimport akka.util.Timeoutimport scala.concurrent.{Await, Future}import scala.concurrent.duration._import scala.util.{Failure, Success}import scala.concurrent.ExecutionContext.Implicits. ...