@@ -125,7 +125,7 @@ public static byte[] getWorkflowExecutionResult(
125
125
TimeUnit unit )
126
126
throws TimeoutException , CancellationException , WorkflowExecutionFailedException ,
127
127
WorkflowTerminatedException , WorkflowTimedOutException , EntityNotExistsError {
128
- // getIntanceCloseEvent waits for workflow completion including new runs.
128
+ // getInstanceCloseEvent waits for workflow completion including new runs.
129
129
HistoryEvent closeEvent =
130
130
getInstanceCloseEvent (service , domain , workflowExecution , timeout , unit );
131
131
return getResultFromCloseEvent (workflowExecution , workflowType , closeEvent );
@@ -294,7 +294,8 @@ private static CompletableFuture<HistoryEvent> getInstanceCloseEventAsync(
294
294
getWorkflowExecutionHistoryAsync (service , request );
295
295
return response .thenComposeAsync (
296
296
(r ) -> {
297
- if (timeout != 0 && System .currentTimeMillis () - start > unit .toMillis (timeout )) {
297
+ long elapsedTime = System .currentTimeMillis () - start ;
298
+ if (timeout != 0 && elapsedTime > unit .toMillis (timeout )) {
298
299
throw CheckedExceptionWrapper .wrap (
299
300
new TimeoutException (
300
301
"WorkflowId="
@@ -310,7 +311,7 @@ private static CompletableFuture<HistoryEvent> getInstanceCloseEventAsync(
310
311
if (history == null || history .getEvents ().size () == 0 ) {
311
312
// Empty poll returned
312
313
return getInstanceCloseEventAsync (
313
- service , domain , workflowExecution , pageToken , timeout , unit );
314
+ service , domain , workflowExecution , pageToken , timeout - elapsedTime , unit );
314
315
}
315
316
HistoryEvent event = history .getEvents ().get (0 );
316
317
if (!isWorkflowExecutionCompletedEvent (event )) {
@@ -326,7 +327,12 @@ private static CompletableFuture<HistoryEvent> getInstanceCloseEventAsync(
326
327
.getWorkflowExecutionContinuedAsNewEventAttributes ()
327
328
.getNewExecutionRunId ());
328
329
return getInstanceCloseEventAsync (
329
- service , domain , nextWorkflowExecution , r .getNextPageToken (), timeout , unit );
330
+ service ,
331
+ domain ,
332
+ nextWorkflowExecution ,
333
+ r .getNextPageToken (),
334
+ timeout - elapsedTime ,
335
+ unit );
330
336
}
331
337
return CompletableFuture .completedFuture (event );
332
338
});
0 commit comments