Skip to content

Instantly share code, notes, and snippets.

@yllan
Created February 16, 2012 01:33
Show Gist options
  • Select an option

  • Save yllan/1840635 to your computer and use it in GitHub Desktop.

Select an option

Save yllan/1840635 to your computer and use it in GitHub Desktop.
Create Non-Blocking response
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