How do we get the first completed Async Activity?

I couldn’t find an example online but it seems like when we call multiple async activities there is no elegant way of knowing which one has completed first.In a normal case I would use Java CompletionService which gives the first Future that completed. But in the case of Temporal I only see running a simply for loop and doing a synchronous wait on the promise.get()

You can use


where promiseList is a List<Promise> which can contain your Async.function calls, for example:

promiseList.add(Async.function(myActivities::doSomething, inputA, inputB));

Hope this helps.

this returns the first completed ones right?

Yes - Promise - temporal-sdk 1.0.9 javadoc

1 Like