vertx-async

Async helpers for Vert.x

License

License

MIT
GroupId

GroupId

org.simondean.vertx
ArtifactId

ArtifactId

vertx-async
Last Version

Last Version

0.1.7
Release Date

Release Date

Type

Type

jar
Description

Description

vertx-async
Async helpers for Vert.x
Project URL

Project URL

https://github.com/simondean/vertx-async
Source Code Management

Source Code Management

https://github.com/simondean/vertx-async.git

Download vertx-async

How to add to project

<!-- https://jarcasting.com/artifacts/org.simondean.vertx/vertx-async/ -->
<dependency>
    <groupId>org.simondean.vertx</groupId>
    <artifactId>vertx-async</artifactId>
    <version>0.1.7</version>
</dependency>
// https://jarcasting.com/artifacts/org.simondean.vertx/vertx-async/
implementation 'org.simondean.vertx:vertx-async:0.1.7'
// https://jarcasting.com/artifacts/org.simondean.vertx/vertx-async/
implementation ("org.simondean.vertx:vertx-async:0.1.7")
'org.simondean.vertx:vertx-async:jar:0.1.7'
<dependency org="org.simondean.vertx" name="vertx-async" rev="0.1.7">
  <artifact name="vertx-async" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.simondean.vertx', module='vertx-async', version='0.1.7')
)
libraryDependencies += "org.simondean.vertx" % "vertx-async" % "0.1.7"
[org.simondean.vertx/vertx-async "0.1.7"]

Dependencies

provided (3)

Group / Artifact Type Version
io.vertx : vertx-core jar 2.1.5
io.vertx : vertx-platform jar 2.1.5
io.vertx : vertx-hazelcast jar 2.1.5

test (3)

Group / Artifact Type Version
junit : junit jar 4.11
io.vertx : testtools jar 2.0.3-final
org.assertj : assertj-core jar 3.0.0

Project Modules

There are no modules declared in this project.

vertx-async

vertx-async is a Vert.x module that provides helper methods for common async patterns. It helps avoid call back hell and is inspired by the API of the popular async node.js module.

Using

The module is available on Maven Central:

<dependency>
  <groupId>org.simondean.vertx</groupId>
  <artifactId>vertx-async</artifactId>
  <version>0.1.1</version>
  <scope>provided</scope>
</dependency>

The module then needs to be added to the includes field of your mod.json:

  "includes": "org.simondean.vertx~vertx-async~0.1.6"

The patterns are all available as static methods on the org.simondean.vertx.async.Async class.

Patterns

Series

  public void seriesExample(AsyncResultHandler<List<String>> handler) {
    Async.<String>series()
      .task(taskHandler -> {
        String result = getSomeResult();
        taskHandler.handle(DefaultAsyncResult.succeed(result));
      })
      .task(taskHandler -> {
        someAsyncMethodThatTakesAHandler(taskHandler);
      })
      .run(result -> {
        if (result.failed()) {
          handler.handle(DefaultAsyncResult.fail(result.cause()));
          return;
        }

        List<String> resultList = result.result();
        doSomethingWithTheResults(resultList);

        handler.handle(DefaultAsyncResult.succeed(resultList));
      });
  }

Waterfall

  public void waterfallExample(AsyncResultHandler<Integer> handler) {
    Async.waterfall()
      .<String>task(taskHandler -> {
        String result = getSomeResult();
        taskHandler.handle(DefaultAsyncResult.succeed(result));
      })
      .<Integer>task((result, taskHandler) -> {
        someAsyncMethodThatTakesAResultAndHandler(result, taskHandler);
      })
      .run(result -> {
        if (result.failed()) {
          handler.handle(DefaultAsyncResult.fail(result.cause()));
          return;
        }

        Integer resultValue = result.result();
        doSomethingWithTheResults(resultValue);

        handler.handle(DefaultAsyncResult.succeed(resultValue));
      });
  }

Each

  public void eachExample(AsyncResultHandler<Void> handler) {
    List<String> list = Arrays.asList("one", "two", "three");

    Async.iterable(list)
      .each((item, eachHandler) -> {
        doSomethingWithItem(item, eachHandler);
      })
      .run(vertx, handler);
  }

Retry

  public void retryExample(AsyncResultHandler<String> handler) {
    Async.retry()
      .<String>task(taskHandler -> {
        someAsyncMethodThatTakesAHandler(taskHandler);
      })
      .times(5)
      .run(result -> {
        if (result.failed()) {
          handler.handle(DefaultAsyncResult.fail(result));
          return;
        }

        String resultValue = result.result();

        doSomethingWithTheResults(resultValue);

        handler.handle(DefaultAsyncResult.succeed(resultValue));
      });
  }

Forever

  public void foreverExample(AsyncResultHandler<String> handler) {
    Async.forever()
      .task(taskHandler -> {
        someAsyncMethodThatTakesAHandler(taskHandler);
      })
      .run(vertx, result -> {
        handler.handle(DefaultAsyncResult.fail(result));
      });
  }

Versions

Version
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1