Skip to content

Commit 8f44379

Browse files
author
Liang Mei
committed
create execution promise in ChildWorkflowStubImpl constructor
1 parent 13c936b commit 8f44379

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/main/java/com/uber/cadence/internal/sync/ChildWorkflowStubImpl.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ class ChildWorkflowStubImpl implements ChildWorkflowStub {
3535
private final String workflowType;
3636
private final ChildWorkflowOptions options;
3737
private final WorkflowInterceptor decisionContext;
38-
private CompletablePromise<WorkflowExecution> execution;
38+
private final CompletablePromise<WorkflowExecution> execution;
39+
private boolean executionStarted;
3940

4041
ChildWorkflowStubImpl(
4142
String workflowType, ChildWorkflowOptions options, WorkflowInterceptor decisionContext) {
4243
this.workflowType = Objects.requireNonNull(workflowType);
4344
this.options = new ChildWorkflowOptions.Builder(options).validateAndBuildWithDefaults();
4445
this.decisionContext = Objects.requireNonNull(decisionContext);
46+
this.execution = Workflow.newPromise();
4547
}
4648

4749
@Override
@@ -51,13 +53,6 @@ public String getWorkflowType() {
5153

5254
@Override
5355
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-
}
6156
return execution;
6257
}
6358

@@ -87,14 +82,14 @@ public <R> R execute(Class<R> returnType, Object... args) {
8782
public <R> Promise<R> executeAsync(Class<R> returnType, Object... args) {
8883
WorkflowResult<R> result =
8984
decisionContext.executeChildWorkflow(workflowType, returnType, args, options);
90-
execution = Workflow.newPromise();
9185
execution.completeFrom(result.getWorkflowExecution());
86+
executionStarted = true;
9287
return result.getResult();
9388
}
9489

9590
@Override
9691
public void signal(String signalName, Object... args) {
97-
if (execution == null) {
92+
if (!executionStarted) {
9893
throw new IllegalStateException(
9994
"This stub cannot be used to signal a workflow"
10095
+ " without starting it first. "

0 commit comments

Comments
 (0)