Activities (async) sample.
// Workflow method impl / workflow function
public String asyncactivities(String name) {
Promise<String> res1 = Async.function(activities::doSomething, name);
Promise<String> res2 = Async.function(activities::doSomethingElse, name);
String r1 = res1.get();
String r2 = res2.get();
return r1 + r2;
}
History:
- WorkflowExecutionStarted
- WorkflowTaskScheduled
- WorkflowTaskStarted
- WorkflowTaskCompleted
- ActivityTaskScheduled
- ActivityTaskScheduled
4,5,6 are important here. So your worker has executed the three lines:
Promise res1 = Async.function(activities::doSomething, name);
Promise res2 = Async.function(activities::doSomethingElse, name);
which are two futures, and then
res1.get()
is a blocking code which requires us to wait for the results of the res1 promise.
Events 5 and 6 are the events server wrote into history that correspond to the two ScheduleActivity commands that worker has sent to it, one for each of the async activity invocations we requested in code.
- ActivityTaskStarted (exec of activity started)
- ActivityTaskCompleted (exec of activity completed)
- WorkflowTaskScheduled (server asks workers to take a look at progress)
- ActivityTaskStarted (exec of activity started)
- ActivityTaskCompleted (exec of activity completed)
This is a little bit of an optimization that is done by Temporal, in this example the two async activities completed very fast. The first blocking call to res1.get();
was unblocked but since both activities completed they can be handled within the same workflow task. So the second blocking call res2.get();
was unblocked right away since the res2 activity result was already available in history.
- WorkflowTaskStarted
- WorkflowTaskCompleted
Worker has executed the return statement
- WorkflowExecutionCompleted (server records exec completed)
Hope this helps.