Created
April 21, 2012 04:08
-
-
Save jto/2433882 to your computer and use it in GitHub Desktop.
humf
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._ | |
import play.api.mvc._ | |
import play.api.libs.ws._ | |
import play.api.libs.iteratee._ | |
import play.api.libs.concurrent._ | |
object Application extends Controller { | |
val EXPECTED_LENGTH = 15; | |
def index = Action { | |
val p1 = WS.url("http://linkedin.com").get().map{ _ => "linkedin".toList }.map(Some.apply) | |
val p2 = WS.url("http://zenexity.com").get().map{ _ => "zenexity".toList }.map(Some.apply) | |
val p3 = WS.url("http://news.ycombinator.com").get().map{ _ => "ycombinator".toList }.map(Some.apply) | |
val r = ((Enumerator.fromCallback(() => p1) >- | |
Enumerator.fromCallback(() => p2) >- | |
Enumerator.fromCallback(() => p3)).flatMap{ xs => Enumerator(xs:_*) } &> | |
Enumeratee.take(EXPECTED_LENGTH)) |>> | |
Iteratee.fold(List[Char]()){ (es,e: Char) => e :: es } | |
val p = r.flatMap( _.pureFold( | |
(res, _) => res.toString, | |
_ => "Ouate?", | |
(err, _) => err.toString)) | |
AsyncResult(p.map(s => Ok(s))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment