--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/562e771b-788a-4d05-9025-9f49f4a583a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/b77bc5d8-0e6f-489e-a93e-8c664d1c9ceb%40googlegroups.com.
I agree that's a common pattern, I'm using it a lot, in several Vert.x projects.
public void sendSomething(){ CompletableFuture<Void> future1 = new CompletableFuture<>(); CompletableFuture<Void> futureN = new CompletableFuture<>(); CompletableFuture.allOf(future1, futureN).exceptionally(f->{logger.error(f.getMessage(),f);return null;}).thenAccept( f->{ //everything completed } ); sendAsync(h->{ if(h.succeeded()){ future1.complete(h.result()); }else{ future1.completeExceptionally(h.cause()); } }); sendAsync(h->{ if(h.succeeded()){ futureN.complete(h.result()); }else{ futureN.completeExceptionally(h.cause()); } }); }List<Observable<String>> allObs = new LinkedList<Observable<String>>();
allObs.add(
vertx.deployVerticleObservable(impl, new DeploymentOptions(opts))
.map(r->{return logName;}));
allObs.addAll(
deployKafkaBridgeVerticlesIfNeeded(spec));
Observable<String> all = Observable.merge(allObs);
Now you can subscribe to "all" observable and you put your code in "on complete" function..
all.subscribe(
vertName -> {
System.out.println( vertName + " started ok");
},
err->{
System.out.println("Failed to start :" + err);
err.printStackTrace();
},
() -> {
System.out.println("All configured verticles are started ok.");
}
HTH, Alexi