Last active
December 11, 2015 11:18
-
-
Save brikis98/4592742 to your computer and use it in GitHub Desktop.
Play Framework at LinkedIn
This file contains hidden or 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
| package controllers | |
| import play.api.mvc.{Controller, Action, Result} | |
| import play.api.libs.ws.WS | |
| import play.api.libs.json.Json | |
| import play.api.libs.concurrent.Execution.Implicits._ | |
| import scala.concurrent.Future | |
| object Race extends Controller { | |
| def index() = Action { | |
| Async { | |
| val start = System.currentTimeMillis() | |
| def getLatency(r: Any): Long = System.currentTimeMillis() - start | |
| val googleTime = WS.url("http://www.google.com").get().map(getLatency) | |
| val yahooTime = WS.url("http://www.yahoo.com").get().map(getLatency) | |
| val bingTime = WS.url("http://www.bing.com").get().map(getLatency) | |
| Future.sequence(Seq(googleTime, yahooTime, bingTime)).map { case times => | |
| Ok(Json.toJson(Map("google" -> times(0), "yahoo" -> times(1), "bing" -> times(2)))) | |
| } | |
| } | |
| } | |
| } |
Author
Also, kind of more readable
for(
google <- googleTime;
yahoo <-yahooTime;
bing <-bingTime
) yield Ok(Json.toJson(Map("google" -> google, "yahoo" -> yahoo, "bing" -> bing)))
love,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See The Play Framework at LinkedIn for more info.