No Description

CompletableFutureBuilder.java 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package fr.natan.akkastreamfileprocessingapi.futurecompleteness;
  2. import scala.collection.IndexedSeq;
  3. import scala.concurrent.Future;
  4. import java.util.Random;
  5. import java.util.concurrent.CompletableFuture;
  6. import java.util.concurrent.Executors;
  7. public class CompletableFutureBuilder<T> {
  8. public static<T> CompletableFuture<T> buildcompletableFuture1(Future<T> futureT) {
  9. CompletableFuture<T> completableFuture = new CompletableFuture<>();
  10. Executors.newSingleThreadExecutor().submit(() -> {
  11. while(!futureT.isCompleted()){
  12. Thread.sleep(new Random().nextInt(500-100)+100);
  13. }
  14. completableFuture.complete(futureT.value().get().get());
  15. return null;
  16. });
  17. return completableFuture;
  18. }
  19. public static<T> CompletableFuture<IndexedSeq<T>> buildcompletableFuture2(Future<IndexedSeq<T>> futureListT) {
  20. CompletableFuture<IndexedSeq<T>> completableFuture = new CompletableFuture<>();
  21. Executors.newSingleThreadExecutor().submit(() -> {
  22. while(!futureListT.isCompleted()){
  23. Thread.sleep(100);
  24. }
  25. completableFuture.complete(futureListT.value().get().get());
  26. return null;
  27. });
  28. return completableFuture;
  29. }
  30. }

Powered by TurnKey Linux.