Skip to content

Instantly share code, notes, and snippets.

@ivanovdns
Last active December 23, 2016 10:12
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 ivanovdns/80d5ae159b306537548a85be23b705fc to your computer and use it in GitHub Desktop.
Save ivanovdns/80d5ae159b306537548a85be23b705fc to your computer and use it in GitHub Desktop.
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