O'Reilly logo

Concurrent Patterns and Best Practices by Atul S. Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Actors talking with each another

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required