Home

Awesome

vertx-async

Build Status via Travis CI Coverage Status Codacy Badge Dependency Status Maven Central

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.

<p align="center"> <img style="width:100%" src="https://i.chzbgr.com/full/5068754944/hBECA40C8"></a> </p>

Installation

vertx-async is available on maven central repository and OSSRH repository.

Quick Examples

Each

On a collection

    @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());
        });
    }

On a map

    @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.

Multiple callbacks

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.

Documentation

See our wiki (:construction:).

Collections

eachmapfilterrejectreducetransformdetectsortsomeeveryconcat

Control Flow

seriesparallelwhilstuntilduringforeverwaterfallseq
retryqueueapplyEach (each)timesracecargo

Utils

asyncifyconstantmemoizetimeout