package fr.natan.akkastreamfileprocessingapi.futurecompleteness; import scala.Option; import scala.collection.IndexedSeq; import scala.concurrent.Future; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; public class CompletableFutureBuilder { private static final Logger logger = Logger.getLogger("log"); public static CompletableFuture buildcompletableFuture1(Future> futureT) { CompletableFuture completableFuture = new CompletableFuture<>(); Executors.newSingleThreadExecutor().submit(() -> { while(!futureT.isCompleted()){ try { TimeUnit.MILLISECONDS.sleep(300); } catch (InterruptedException e) { throw new RuntimeException(e); } } T task = futureT.value().get().get().get(); completableFuture.complete(task); }); return completableFuture; } public static CompletableFuture> buildcompletableFuture2(Future> futureIndexedSeqT) { CompletableFuture> completableFuture = new CompletableFuture<>(); Executors.newSingleThreadExecutor().submit(() -> { while (!futureIndexedSeqT.isCompleted()) { try { TimeUnit.MILLISECONDS.sleep(300); } catch (InterruptedException e) { throw new RuntimeException(e); } } IndexedSeq task = futureIndexedSeqT.value().get().get(); completableFuture.complete(task); }); return completableFuture; } }