tillrohrmann commented on a change in pull request #7568: [FLINK-11417] Make 
access to ExecutionGraph single threaded from JobMaster main thread
URL: https://github.com/apache/flink/pull/7568#discussion_r251350093
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/FutureUtils.java
 ##########
 @@ -802,6 +804,89 @@ public void onComplete(Throwable failure, U success) {
                return result;
        }
 
+       /**
+        * This function takes a {@link CompletableFuture} and a function to 
apply to this future. If the input future
+        * is already done, this function returns {@link 
CompletableFuture#thenApply(Function)}. Otherwise, the return
+        * value is {@link CompletableFuture#thenApplyAsync(Function, 
Executor)} with the given executor.
+        *
+        * @param completableFuture the completable future for which we want to 
apply.
+        * @param executor the executor to run the apply function if the future 
is not yet done.
+        * @param applyFun the function to apply.
+        * @param <IN> type of the input future.
+        * @param <OUT> type of the output future.
+        * @return a completable future that is applying the given function to 
the input future.
+        */
+       public static <IN, OUT> CompletableFuture<OUT> applyAsyncIfNotDone(
+               CompletableFuture<IN> completableFuture,
+               Executor executor,
+               Function<? super IN, ? extends OUT> applyFun) {
+               return completableFuture.isDone() ?
 
 Review comment:
   I think this should be fine. There is indeed a race condition between 
completing the future and calling `thenApplyAsync` but in the worst case you 
execute the callback in the supplied executor instead of the calling thread. 
Both paths should work.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to