2525import com .uber .cadence .worker .Worker ;
2626import com .uber .cadence .workflow .Workflow ;
2727import com .uber .cadence .workflow .WorkflowMethod ;
28+ import java .util .concurrent .CompletableFuture ;
29+ import java .util .concurrent .ExecutionException ;
2830import 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