|
25 | 25 | import io.temporal.workflow.ChildWorkflowOptions; |
26 | 26 | import io.temporal.workflow.Promise; |
27 | 27 | import io.temporal.workflow.Workflow; |
28 | | -import java.util.ArrayList; |
29 | | -import java.util.List; |
30 | 28 |
|
31 | 29 | public class ParentWorkflowImpl implements ParentWorkflow { |
32 | 30 | @Override |
33 | 31 | public WorkflowExecution executeParent() { |
34 | 32 |
|
35 | | - final List<Promise<WorkflowExecution>> promises = new ArrayList<>(); |
36 | | - |
37 | | - for (int i = 0; i < 1000; i++) { |
38 | | - // We set the parentClosePolicy to "Abandon" |
39 | | - // This will allow child workflow to continue execution after parent completes |
40 | | - ChildWorkflowOptions childWorkflowOptions = |
41 | | - ChildWorkflowOptions.newBuilder() |
42 | | - .setWorkflowId("childWorkflow" + Math.random()) |
43 | | - .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON) |
44 | | - .build(); |
45 | | - |
46 | | - // Get the child workflow stub |
47 | | - ChildWorkflow child = |
48 | | - Workflow.newChildWorkflowStub(ChildWorkflow.class, childWorkflowOptions); |
49 | | - // Start the child workflow async |
50 | | - Async.function(child::executeChild); |
51 | | - // Get the child workflow execution promise |
52 | | - Promise<WorkflowExecution> childExecution = Workflow.getWorkflowExecution(child); |
53 | | - // Call .get on the promise. This will block until the child workflow starts execution (or |
54 | | - // start |
55 | | - // fails) |
56 | | - |
57 | | - promises.add(childExecution); |
58 | | - } |
59 | | - |
60 | | - Promise.allOf(promises).get(); |
61 | | - |
62 | | - return promises.get(0).get(); |
| 33 | + // We set the parentClosePolicy to "Abandon" |
| 34 | + // This will allow child workflow to continue execution after parent completes |
| 35 | + ChildWorkflowOptions childWorkflowOptions = |
| 36 | + ChildWorkflowOptions.newBuilder() |
| 37 | + .setWorkflowId("childWorkflow") |
| 38 | + .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON) |
| 39 | + .build(); |
| 40 | + |
| 41 | + // Get the child workflow stub |
| 42 | + ChildWorkflow child = Workflow.newChildWorkflowStub(ChildWorkflow.class, childWorkflowOptions); |
| 43 | + // Start the child workflow async |
| 44 | + Async.function(child::executeChild); |
| 45 | + // Get the child workflow execution promise |
| 46 | + Promise<WorkflowExecution> childExecution = Workflow.getWorkflowExecution(child); |
| 47 | + // Call .get on the promise. This will block until the child workflow starts execution (or start |
| 48 | + // fails) |
| 49 | + return childExecution.get(); |
63 | 50 | } |
64 | 51 | } |
0 commit comments