-
-
Save ivanovdns/80d5ae159b306537548a85be23b705fc to your computer and use it in GitHub Desktop.
CompositionFuture
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
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