vertx-async is a portage of caolan/async nodejs module to Vert.x framework that provides helpers methods for common async patterns.
Async provides many methods that include the usual 'functional' suspects (map
, reduce
, filter
, each
…) as well as some common patterns for asynchronous control flow (parallel
, series
, waterfall
…). All these functions assume you follow the vert.x convention.
vertx-async is available on maven central repository and OSSRH repository.
@Override
public void start(final Future<Void> startFuture) {
AsyncFactorySingleton.getInstance().createCollections(context)
.each(IntStream.iterate(0, i -> i + 1).limit(100).boxed().collect(Collectors.toList()), (item, handler) -> {
System.out.println("get " + item);
handler.handle(DefaultAsyncResult.succeed());
}, e -> {
System.out.println("done.");
startFuture.complete(e.result());
});
}
@Override
public void start(final Future<Void> startFuture) {
AsyncFactorySingleton.getInstance().createCollections(context)
.each(IntStream.iterate(0, i -> i + 1).limit(100).boxed().collect(Collectors.toMap(p -> p.toString(), Function.identity())), (item, handler) -> {
System.out.println(item.getKey() + " -> " + item.getValue());
handler.handle(DefaultAsyncResult.succeed());
}, e -> {
System.out.println("done.");
startFuture.complete(e.result());
});
}
There are many more functions available so take a look at the wiki for a full list (work in progress) . This README aims to be comprehensive, so if you feel anything is missing please create a GitHub issue for it.
Make sure to always calling the callback handler once, instead of a return
procedural programming statement style, otherwise you will cause multiple callbacks and unpredictable behavior in many cases.
See our wiki (:construction:).
each | map | filter | reject | reduce | transform | detect | sort | some | every | concat |
series | parallel | whilst | until | during | forever | waterfall | seq |
retry | queue | applyEach (each) | times | race | cargo |
asyncify | constant | memoize | timeout |