List<String> evt = new ArrayList<String>();
evt
.add("evt.step1");
evt
.add("evt.step2");
evt
.add("evt.step3");
//
vertx.eventBus().send(evt.get(0), "test", ar -> {
vertx.eventBus().send(evt.get(1), "test", ar -> {
vertx.eventBus().send(evt.get(2), "test", ar -> {
})
})
});
List<String> evt = new ArrayList<String>();
evt.add("evt.step1");
evt.add("evt.step2");
evt.add("evt.step3");
Async.create(evt)
.series((event, next) -> {
vertx.eventBus().send(event, "test", ar -> {
next.handle(null);
});
},
(error) -> {
System.out.println("ending process list");
}
);
it uses the same syntax that the populat Async lib in nodejs.
your use case seems to be a tad specific to be provided out of the box by a library.
Personally I think I'd go a different way on this and build up a list of Supplier<CompletableFuture>, then use the streaming API to call reduce, taking advantage of the CompletableFuture's ability to call thenAccept/thenApply/thenCompose to act on the result of the future. I've had to do similar in the pac4j-async library I'm working on when we want to ensure that certain async operations are processed in serial rather than parallel.
List<String> evt = new ArrayList<String>();
evt.add("evt.step1");
evt.add("evt.step2");
evt.add("evt.step3");
//
vertx.eventBus().send(evt.get(0), "test", ar -> {
vertx.eventBus().send(evt.get(1), "test", ar -> {
vertx.eventBus().send(evt.get(2), "test", ar -> {
})
})
});
On Friday, August 18, 2017 at 1:16:01 PM UTC+1, Julien Viet wrote:
See allInSequence in https://github.com/millross/pac4j-async/blob/master/pac4j-async-core/src/main/java/org/pac4j/async/core/future/FutureUtils.javaand its tests in https://github.com/millross/pac4j-async/blob/master/pac4j-async-core/src/test/java/org/pac4j/async/core/future/FutureUtilsTest.javaNote that in your case you get a Supplier<CompletableFuture<Void>>by creating a method such as (not tested in IDE, but you should get the idea)Supplier<CompletableFuture<Void>> sendAndReply(final String address) {return () -> {CompletableFuture<Void> future = new CompletableFuture<Void>();vertx.eventBus().send(address, "test, ar -> {if (ar.successful()) {future.complete(null);} else {future.completeExceptionally(ar.cause);}});return future;}}Note that it's pretty easy to turn that method into a general pattern to complete a completablefuture from an async result, and easily wrap sends where you do some additional processing prior to completing the future, and then you can use the reduce approach as shown in my links.