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 iterator = if (dir.isDirectory) dir.listFiles.iterator else Iterator.empty } Seq(dir) ++: itsChildren.flatMap(recurseIntoDir(_)) } def receive = { // 5 case FileFinderMsg(pat, rootDir) =>...