Created
February 16, 2012 01:33
-
-
Save yllan/1840635 to your computer and use it in GitHub Desktop.
Create Non-Blocking response
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
| def index = Action { | |
| val slowFetch: Promise[Response] = WS.url("http://fetch.some.data/").get | |
| val asyncResult: Promise[Result] = slowFetch.orTimeout("Can't get data", 10000).map { eitherResponseOrTimeout ⇒ | |
| eitherResponseOrTimeout.fold( | |
| timeout ⇒ InternalServerError(timeout), | |
| response ⇒ Ok("Fetched " + response.body) | |
| ) | |
| } | |
| Async { | |
| asyncResult | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment