@@ -35,13 +35,15 @@ class ChildWorkflowStubImpl implements ChildWorkflowStub {
35
35
private final String workflowType ;
36
36
private final ChildWorkflowOptions options ;
37
37
private final WorkflowInterceptor decisionContext ;
38
- private CompletablePromise <WorkflowExecution > execution ;
38
+ private final CompletablePromise <WorkflowExecution > execution ;
39
+ private boolean executionStarted ;
39
40
40
41
ChildWorkflowStubImpl (
41
42
String workflowType , ChildWorkflowOptions options , WorkflowInterceptor decisionContext ) {
42
43
this .workflowType = Objects .requireNonNull (workflowType );
43
44
this .options = new ChildWorkflowOptions .Builder (options ).validateAndBuildWithDefaults ();
44
45
this .decisionContext = Objects .requireNonNull (decisionContext );
46
+ this .execution = Workflow .newPromise ();
45
47
}
46
48
47
49
@ Override
@@ -51,13 +53,6 @@ public String getWorkflowType() {
51
53
52
54
@ Override
53
55
public Promise <WorkflowExecution > getExecution () {
54
- // Technically we can create and return a promise here in case the workflow is not started, and
55
- // create a separate started flag for signal method to check.
56
- // We don't expect this to be a critical issue for client users so we choose the simpler
57
- // approach of checking and throwing exception for now.
58
- if (execution == null ) {
59
- throw new IllegalStateException ("Workflow has not started." );
60
- }
61
56
return execution ;
62
57
}
63
58
@@ -87,14 +82,14 @@ public <R> R execute(Class<R> returnType, Object... args) {
87
82
public <R > Promise <R > executeAsync (Class <R > returnType , Object ... args ) {
88
83
WorkflowResult <R > result =
89
84
decisionContext .executeChildWorkflow (workflowType , returnType , args , options );
90
- execution = Workflow .newPromise ();
91
85
execution .completeFrom (result .getWorkflowExecution ());
86
+ executionStarted = true ;
92
87
return result .getResult ();
93
88
}
94
89
95
90
@ Override
96
91
public void signal (String signalName , Object ... args ) {
97
- if (execution == null ) {
92
+ if (! executionStarted ) {
98
93
throw new IllegalStateException (
99
94
"This stub cannot be used to signal a workflow"
100
95
+ " without starting it first. "
0 commit comments