Skip to content

Instantly share code, notes, and snippets.

@ahoy-jon
Created August 7, 2012 13:57
Show Gist options
  • Save ahoy-jon/3285561 to your computer and use it in GitHub Desktop.
Save ahoy-jon/3285561 to your computer and use it in GitHub Desktop.
Pick your poison
val log = new {def warn(a:Any) {}}
val timeoutWarn = () => log.warn("Actor ask timed-out while calling HttpClient")
def handleTimeouts[A](response : Option[(Int, Option[String])],
method : (Int, Option[String]) => List[A]):List[A] = {
// method application .... or warning on timeout and emptyList
response.map(method.tupled(_)).getOrElse({timeoutWarn(); List.empty[A]})
}
def handleTimeouts2[A](response : Option[(Int, Option[String])],
method : (Int, Option[String]) => List[A]):List[A] = {
// method application or warning on timeout
response match {
case Some(res) => method.tupled(res)
case None => timeoutWarn(); List.empty[A]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment