Skip to content

Instantly share code, notes, and snippets.

@purplefox
Last active June 7, 2017 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplefox/b7a6ca5fc719a6e59580e18d56af1865 to your computer and use it in GitHub Desktop.
Save purplefox/b7a6ca5fc719a6e59580e18d56af1865 to your computer and use it in GitHub Desktop.
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