Last active
January 9, 2016 01:26
-
-
Save pedroarthur/e5f82bd1e5d2852ed4ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* imports suppressed */ | |
class MemoizingActor(actual: ActorRef) extends Actor { | |
case class DropState(message: Any) | |
override def receive: Actor.Receive = actualReceive(Map()) | |
def actualReceive(data: Map[Any, Future[Any]]): Receive = { | |
case DropState(any) => | |
context become actualReceive(data - any) | |
case any: Any => | |
val future = data getOrElse (any, { | |
(actual ? any) andThen { case _ => self ! DropState(any) } | |
}) pipeTo sender | |
context become actualReceive(data + (any -> future)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment