Created
May 23, 2020 22:34
-
-
Save dkomanov/f81713f6b2f7ec2beb775445aba6b9f5 to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-2] RPC with caching 2
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
val handlers: List[HttpRequest => Future[Option[Int]]] = List( | |
handleFromMemcached, | |
handleFromCdn, | |
r => handleFromHadoop(r).map(Some.apply) | |
) | |
def handle(r: HttpRequest): Future[Int] = { | |
executeLazily(handlers.map(handler => () => handler(r))) | |
.map(_.getOrElse(throw new IllegalStateException("Hadoop should always return Some!"))) | |
} | |
def executeLazily(list: List[() => Future[Option[Int]]]): Future[Option[Int]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment