shuai-xu 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_r251275059
########## 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 am not sure whether it is thread safe? for example, when executing isDone, the future is not completed, but when executing thenApplyAsync, the future is done. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services