Created
May 22, 2012 19:34
-
-
Save andyczerwonka/2771131 to your computer and use it in GitHub Desktop.
I'm trying to understand how to best deal with sending an async request to a web service
This file contains 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 measures(user: User): List[Measure] = { | |
val prefs = UserPreferences.findByUser(user) // get my prefs | |
val request = generateRequest(prefs) // build up a WS request | |
val promise = WS.url(exportEndpoint).post(request) | |
promise.orTimeout(Nil, 100000).map { responseOrTimeout => | |
responseOrTimeout.fold( | |
response => { | |
val body = promise.value.get.body | |
val lines = body.split("\n").map(_.split(",")) | |
lines.map { | |
case Array(a, b, c) => Measure( | |
a.substring(1, a.length() - 1), | |
dateFrom(b.substring(1, b.length() - 1)), | |
c.substring(1, c.length() - 1).toDouble) | |
}.toList | |
}, | |
timeout => Nil) | |
}.value.get | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks - now things are making more sense. I made changes to the gist to reflect the correct API.