17
17
18
18
package com .uber .cadence .samples .spring .workflows .impl ;
19
19
20
+ import com .uber .cadence .WorkflowExecution ;
20
21
import com .uber .cadence .samples .spring .models .SampleMessage ;
21
22
import com .uber .cadence .samples .spring .workflows .ChildWorkflow ;
22
23
import com .uber .cadence .samples .spring .workflows .ParentWorkflow ;
24
+ import com .uber .cadence .workflow .Async ;
25
+ import com .uber .cadence .workflow .Promise ;
23
26
import com .uber .cadence .workflow .Workflow ;
24
27
25
28
public class ParentWorkflowImpl implements ParentWorkflow {
@@ -29,4 +32,20 @@ public String getGreetingInParent(SampleMessage sampleMessage) {
29
32
ChildWorkflow childWorkflow = Workflow .newChildWorkflowStub (ChildWorkflow .class );
30
33
return childWorkflow .greetInChild (sampleMessage .GetMessage ());
31
34
}
35
+
36
+ // This example allows parent workflow returns first and leave child workflow keep running.
37
+ private String runChildWorkflowAsync (SampleMessage sampleMessage ) {
38
+ ChildWorkflow childWorkflow = Workflow .newChildWorkflowStub (ChildWorkflow .class );
39
+ // non-blocking call that starts the child workflow
40
+ Async .function (childWorkflow ::greetInChild , sampleMessage .GetMessage ());
41
+
42
+ // Directly invoking child workflow method is a blocking call. It will block the thread
43
+ // until child workflow completes. In this example, parent workflow will immediately
44
+ // and keep child workflow running.
45
+ Promise <WorkflowExecution > childWorkflowPromise = Workflow .getWorkflowExecution (childWorkflow );
46
+ // block until child workflow started, otherwise parent workflow may completes first
47
+ // before child workflow even starts.
48
+ childWorkflowPromise .get ();
49
+ return "child can keep running, parent return first" ;
50
+ }
32
51
}
0 commit comments