Waiting for workflow completion

After starting a workflow asynchronously, I want to wait for its completion but with a timeout. For example, the WorkflowExecutionTimeout is set to 60 seconds while starting the workflow asynchronously. But I want to wait only for 10 seconds and then return to the caller. The workflow should continue to execute for 60 seconds.

How can I achieve this? I did not find any API to specify the 10 seconds timeout while reconnecting to the already started workflow. I referred to the page https://docs.temporal.io/docs/java-starting-workflow-executions/ (the API also seems to have changed from the example shown on this page).

You can use WorkflowStub.getResult:

      WorkflowExecution execution = WorkflowClient.start(workflow::workflow1, "input1");
      WorkflowStub untyped = WorkflowStub.fromTyped(workflow);
      String result = untyped.getResult(10, TimeUnit.SECONDS, String.class);

Thanks Maxim, it worked.

1 Like