diff --git a/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java b/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java index 79f20336b..cd5f8c5f2 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java @@ -21,10 +21,12 @@ import com.google.common.base.Throwables; import io.temporal.activity.ActivityOptions; +import io.temporal.client.UpdateHandle; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.client.WorkflowUpdateException; +import io.temporal.client.WorkflowUpdateStage; import io.temporal.failure.ApplicationFailure; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; @@ -250,6 +252,17 @@ public static void main(String[] args) throws Exception { WorkflowStub greetingStub = client.newUntypedWorkflowStub(WORKFLOW_ID); greetingStub.update("addGreeting", int.class, "Temporal"); + /* + * Use the untyped stub to start an update, but wait only until it's + * accepted, receiving an update handle in return. Then use the update + * handle to get the result. + */ + UpdateHandle updateHandle = + greetingStub.startUpdate( + "addGreeting", WorkflowUpdateStage.ACCEPTED, int.class, "Started asynchronously"); + + updateHandle.getResultAsync().get(); + try { // The update request will fail on a empty name and the exception will be thrown here. workflowById.addGreeting("");