25
25
import com .uber .cadence .worker .Worker ;
26
26
import com .uber .cadence .workflow .Workflow ;
27
27
import com .uber .cadence .workflow .WorkflowMethod ;
28
+ import java .util .concurrent .CompletableFuture ;
29
+ import java .util .concurrent .ExecutionException ;
28
30
import java .util .concurrent .ForkJoinPool ;
29
31
30
32
/**
@@ -97,7 +99,7 @@ private void composeGreetingAsync(byte[] taskToken, String greeting, String name
97
99
}
98
100
}
99
101
100
- public static void main (String [] args ) {
102
+ public static void main (String [] args ) throws ExecutionException , InterruptedException {
101
103
// Start a worker that hosts both workflow and activity implementation
102
104
Worker worker = new Worker (DOMAIN , TASK_LIST );
103
105
// Workflows are stateful. So need a type to create instances.
@@ -111,9 +113,12 @@ public static void main(String[] args) {
111
113
WorkflowClient workflowClient = WorkflowClient .newInstance (DOMAIN );
112
114
// Get a workflow stub using the same task list the worker uses.
113
115
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 ());
117
122
System .exit (0 );
118
123
}
119
124
}
0 commit comments