Akka actors take the stage

Akka is a Scala library, which let's us implement the message-based concurrency systems. An actor is like a small program with a message queue of its own. You can only get an actor to do some work by passing it a message.

Here is our FileFinder object as an actor:

import akka.actor._
import akka.util.Timeout
import scala.io.Source

object FileFinder { // 1
  def props() = Props(new FileFinder)
  case class FileFinderMsg(pat: String, rootDir: String)
}

class FileFinder extends Actor { // 2 
  import FileFinder._
  import context._
  import java.io.File

  val grepActor = system.actorOf(Props(new GrepAFile), ""GrepAFile"") // 3

  def recurseIntoDir(dir: File): Iterable[File] = { // 4
    val itsChildren = new Iterable[File] {
 def ...

Get Scala Functional Programming Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.