Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[writing-async-app-in-scala-part-2] RPC with caching 2
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