Async activities in workflow

Currently I am trying to execute some activities in workflow by Async.function.

        List<Promise> listOfPromise = new ArrayList();
        listOfPromise.add(Async.function(account::consume, dto).thenApply((m)->{
            saga.addCompensation(account::refund, dto);
            return null;
        }));
        // .....
        finalResult = Promise.allOf(listOfPromise.toArray(new Promise [listOfPromise.size()]));
        finalResult.cancellableGet();

How can I wait until all activities tasks get completed (whatever failed and successes ).

1 Like

Use the loop:

        for(Promise p: listOfPromise) {
            try {
                p.get();
            } catch (Exception e) {
                // handle error
            }
        }

Oh, thanks, I found that once the get() is called, all the async activities will be fired to process.
This is exactly what I want to do.