Created
May 29, 2013 17:14
-
-
Save chirino/5672008 to your computer and use it in GitHub Desktop.
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 example | |
| import org.vertx.java.core._ | |
| import org.vertx.java.core.buffer._ | |
| import org.vertx.java.core.http._ | |
| import scala.concurrent._ | |
| import scala.concurrent.duration._ | |
| import scala.async.Async.{async, await} | |
| import scala.util.{Try,Success,Failure} | |
| import scala.concurrent.duration._ | |
| import org.vertx.java.core.Handler; | |
| import org.vertx.java.core.eventbus.Message; | |
| import org.vertx.java.platform.Verticle; | |
| class Example extends Verticle { | |
| def request(host:String, path:String) = { | |
| val promise = Promise[Buffer]() | |
| println("Requesting: "+host) | |
| vertx.createHttpClient().setPort(80).setHost(host).getNow(path, new Handler[HttpClientResponse]() { | |
| def handle(response:HttpClientResponse) = { | |
| response.bodyHandler(new Handler[Buffer]() { | |
| def handle(data:Buffer) { | |
| promise complete Success(data) | |
| } | |
| }) | |
| } | |
| }) | |
| promise.future | |
| } | |
| override def start = { | |
| println("starting") | |
| import ExecutionContext.Implicits.global | |
| async { | |
| val google = await(request("google.com", "/")) | |
| println("Google came in") | |
| val yahoo = await(request("yahoo.com", "/")) | |
| println("Yahoo came in") | |
| println("===================\n"+google +"\n===================\n"+ yahoo) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment