Last active
June 7, 2017 14:36
-
-
Save purplefox/b7a6ca5fc719a6e59580e18d56af1865 to your computer and use it in GitHub Desktop.
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
public void testFoo() { | |
Vertx vertx = Vertx.vertx(); | |
HttpClient client = vertx.createHttpClient(); | |
getWithFuture(client, "url1") | |
.thenCompose(resp1 -> getWithFuture(client, "url2/" + resp1.statusMessage())) | |
.thenCompose(resp2 -> getWithFuture(client, "url3/" + resp2.statusMessage())) | |
.whenComplete(((resp3, t) -> { | |
if (t != null) { | |
t.printStackTrace(); | |
} else { | |
System.out.println("All done"); | |
} | |
})); | |
} | |
private CompletableFuture<HttpClientResponse> getWithFuture(HttpClient client, String url) { | |
CompletableFuture<HttpClientResponse> cf = new CompletableFuture<>(); | |
HttpClientRequest req = client.get(url); | |
req.exceptionHandler(cf::completeExceptionally); | |
req.handler(cf::complete); | |
return cf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment