Start Methods In Parallel

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

A running workflow instance can have multiple methods running in parallel. When it's the case, those executions share the internal properties of this workflow instance.

This can be used to trigger new actions or to access or update the workflow properties.

// create stub of a running HelloWorld workflow
HelloWorld helloworld = client.getWorkflowById(HelloWorld.class, id);

// running `HelloWorld::method` of the targeted workflow without waiting for the result
Deferred<Boolean> deferred = client.dispatch(helloworld::method, ...);

// running `HelloWorld::method` on the targeted workflow and wait for its boolean result
Boolean result = helloworld.method(...);
// create stub of a running HelloWorld workflow
val helloworld: HelloWorld = client.getWorkflowById(HelloWorld::class.java, id)

// running `HelloWorld::method` of the targeted workflow without waiting for the result
val deferred: Deferred<Boolean> = client.dispatch(helloworld::method, ...)

// running `HelloWorld::method` on the targeted workflow and wait for its boolean result
val result = helloworld.method(...)

Due to some Java syntax constraints, if the return type of the method used is void, we need to use dispatchVoid function instead of dispatch.

Another way to target some running workflows is to used the getWorkflowByTag function that take a workflow interface and a tag as parameter. For example:

// create the stub of running HelloWorld workflows with tag
private final HelloWorld helloworld = getWorkflowByTag(HelloWorld.class, tag);

// running `HelloWorld::method` of the targeted workflows without waiting for the boolean result
val deferred: Deferred<Boolean> = client.dispatch(helloworld::method, ...);
// create the stub of running workflows with tag
private val helloworld: HelloWorld = getWorkflowByTag(HelloWorld::class.java, tag)

// running `HelloWorld::method` of the targeted workflow without waiting for the boolean result
val deferred: Deferred<Boolean> = client.dispatch(helloworld::method, ...)

In the example above, the "HelloWorld::method" will run on all workflows having the tag.

When targeting workflows by tag, it's not possible to retrieve deferred.id or to do deferred.await(), as the deferred can target multiple instances.

Edit this page on GitHub Updated at Sun, May 22, 2022