Skip to content

Instantly share code, notes, and snippets.

@ivanovdns ivanovdns/comp.java Secret
Last active Dec 23, 2016

Embed
What would you like to do?
CompositionFuture
import io.vertx.core.AbstractVerticle;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.Launcher;
import io.vertx.core.eventbus.EventBus;
import java.util.ArrayList;
import java.util.List;
public class ServiceConnector extends AbstractVerticle {
public static void main(String[] args) {
Launcher.main(new String[]{"run", ServiceConnector.class.getName()});
}
@Override
public void start() {
EventBus eb = vertx.eventBus();
List<Future> futureList = new ArrayList<Future>();
for (int i = 0; i < 5; i++) {
futureList.add(Future.future());
}
CompositeFuture.all(futureList).setHandler(fHdl -> {
System.out.println("All composition");
for (int i = 0; i < fHdl.result().list().size(); i++) {
System.out.println("result: " + fHdl.result().list().get(i).toString());
}
});
for (int i = 4; i >= 0; i--) {
Future<String> future = futureList.get(i);
future.complete("result: "+i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.