Skip to content

Commit 822d26d

Browse files
authored
Add example for async child start (#32)
1 parent 461f119 commit 822d26d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/com/uber/cadence/samples/hello/HelloChild.java

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static com.uber.cadence.samples.common.SampleConstants.DOMAIN;
2121

22+
import com.uber.cadence.WorkflowExecution;
2223
import com.uber.cadence.client.WorkflowClient;
2324
import com.uber.cadence.worker.Worker;
2425
import com.uber.cadence.workflow.Async;
@@ -58,6 +59,20 @@ public String getGreeting(String name) {
5859
// Do something else here.
5960
return greeting.get(); // blocks waiting for the child to complete.
6061
}
62+
63+
// This example shows how parent workflow return right after starting a child workflow,
64+
// and let the child run itself.
65+
private String demoAsyncChildRun(String name) {
66+
GreetingChild child = Workflow.newChildWorkflowStub(GreetingChild.class);
67+
// non blocking call that initiated child workflow
68+
Async.function(child::composeGreeting, "Hello", name);
69+
// instead of using greeting.get() to block till child complete,
70+
// sometimes we just want to return parent immediately and keep child running
71+
Promise<WorkflowExecution> childPromise = Workflow.getWorkflowExecution(child);
72+
childPromise.get(); // block until child started,
73+
// otherwise child may not start because parent complete first.
74+
return "let child run, parent just return";
75+
}
6176
}
6277

6378
/**

0 commit comments

Comments
 (0)