Fan-Out

Infinitic is still in active development. Subscribe here to follow the progress.

The internal async function provides a way to run some parts of our workflows in parallel. For example:

task.a1();

async(() -> {
    task.b1();
    return task.b2();
});

task.a2();
task.a3();
task.a1()

async {
    task.b1()
    task.b2()
}

task.a2()
task.a3()

If we are dispatching a single task or a single child-workflow, it's internally more efficient to use the following syntax:

async(task, t -> t.method(parameters);
async(task) { method(parameters) }

The return value of a async function is a io.infinitic.workflows.Deferred<T>, T being the type of the return value of the provided lambda / method.

A Deferred has some useful methods:

  • await(): waits for the completion (or cancellation) of the deferred and returns its result
  • isCompleted(): boolean indicating if this Deferred is completed by now
  • isCanceled(): boolean indicating if this Deferred is canceled by now
  • isOngoing(): boolean indicating if this Deferred is still ongoing

Those methods can be used in the workflow, for example:

task.a1();

Deferred<String> deferred = async(() -> {
    task.b1();
    return task.b2();
});

task.a2();

if (deferred.isOngoing()) {
    task.a3();
}

String o = deferred.await()

task.a4(o);
task.a1()

val deferred = async {
    task.b1()
    task.b2()
}

task.a2()

if (deferred.isOngoing()) {
    task.a3()
}

val o = deferred.await()

task.a4(o);

Edit this page on GitHub Updated at Fri, May 28, 2021