Skip to content

Commit f89cd5d

Browse files
authored
Changed HelloAsyncActvityCompletion to use WorkflowClient.execute (#13)
1 parent 18fa353 commit f89cd5d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.uber.cadence.worker.Worker;
2626
import com.uber.cadence.workflow.Workflow;
2727
import com.uber.cadence.workflow.WorkflowMethod;
28+
import java.util.concurrent.CompletableFuture;
29+
import java.util.concurrent.ExecutionException;
2830
import java.util.concurrent.ForkJoinPool;
2931

3032
/**
@@ -97,7 +99,7 @@ private void composeGreetingAsync(byte[] taskToken, String greeting, String name
9799
}
98100
}
99101

100-
public static void main(String[] args) {
102+
public static void main(String[] args) throws ExecutionException, InterruptedException {
101103
// Start a worker that hosts both workflow and activity implementation
102104
Worker worker = new Worker(DOMAIN, TASK_LIST);
103105
// Workflows are stateful. So need a type to create instances.
@@ -111,9 +113,12 @@ public static void main(String[] args) {
111113
WorkflowClient workflowClient = WorkflowClient.newInstance(DOMAIN);
112114
// Get a workflow stub using the same task list the worker uses.
113115
GreetingWorkflow workflow = workflowClient.newWorkflowStub(GreetingWorkflow.class);
114-
// Execute a workflow waiting for it complete.
115-
String greeting = workflow.getGreeting("World");
116-
System.out.println(greeting);
116+
// Execute a workflow returning a future that can be used to wait for the workflow
117+
// completion.
118+
CompletableFuture<String> greeting = WorkflowClient.execute(workflow::getGreeting,
119+
"World");
120+
// Wait for workflow completion
121+
System.out.println(greeting.get());
117122
System.exit(0);
118123
}
119124
}

0 commit comments

Comments
 (0)