Skip to content

Instantly share code, notes, and snippets.

@chessman
Created August 17, 2016 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chessman/8e69b00ad4ebeff500aac0e537ebb8af to your computer and use it in GitHub Desktop.
Save chessman/8e69b00ad4ebeff500aac0e537ebb8af to your computer and use it in GitHub Desktop.
akka-http with finagle
import com.twitter.{ util => twitter }
path("/") {
val result = client1.getThings1 flatMap { things1 =>
...
client2.getThings2 flatMap { things2 =>
...
twitter.Future.join(client3.getThings3, client4.getThings4)
}
//version 1
Await.result(result.liftToTry, 10.seconds) match {
case twitter.Return(result) => complete(result)
case twitter.Throw(ex) => complete((StatusCodes.InternalServerError, s"Error: $ex"))
}
//version 2
onComplete(twitterFutureToScalaFuture(result)) {
case Success(result) => complete(result)
case Failure(ex) => complete((StatusCodes.InternalServerError, s"Error: $ex"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment