1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package fr.natan.akkastreamfileprocessingapi.futurecompleteness;
-
-
- import scala.collection.IndexedSeq;
- import scala.concurrent.Future;
-
- import java.util.Random;
- import java.util.concurrent.CompletableFuture;
- import java.util.concurrent.Executors;
-
-
-
- public class CompletableFutureBuilder<T> {
-
- public static<T> CompletableFuture<T> buildcompletableFuture1(Future<T> futureT) {
- CompletableFuture<T> completableFuture = new CompletableFuture<>();
- Executors.newSingleThreadExecutor().submit(() -> {
- while(!futureT.isCompleted()){
- Thread.sleep(new Random().nextInt(500-100)+100);
- }
- completableFuture.complete(futureT.value().get().get());
- return null;
- });
-
- return completableFuture;
- }
-
- public static<T> CompletableFuture<IndexedSeq<T>> buildcompletableFuture2(Future<IndexedSeq<T>> futureListT) {
- CompletableFuture<IndexedSeq<T>> completableFuture = new CompletableFuture<>();
- Executors.newSingleThreadExecutor().submit(() -> {
- while(!futureListT.isCompleted()){
- Thread.sleep(100);
- }
- completableFuture.complete(futureListT.value().get().get());
- return null;
- });
-
- return completableFuture;
- }
-
- }
|