Java Thread Future transferResult(final CompletionStage source, final CompletableFuture target)

Here you can find the source of transferResult(final CompletionStage source, final CompletableFuture target)

Description

Internal JVM SDK util.

License

Apache License

Parameter

Parameter Description
source the stage which may be completed at some time
target future which will receive the results of source
T type of the value of the future

Declaration

public static <T> void transferResult(final CompletionStage<T> source,
                                  final CompletableFuture<T> target) 

Method Source Code

    //package com.java2s;
    //License from project: Apache License 

    import java.util.concurrent.*;

    public class Main {
        /**/*w  w  w .  ja  v  a2s .c  o  m*/
         * Internal JVM SDK util.
         *
         * @param source the stage which may be completed at some time
         * @param target future which will receive the results of source
         * @param <T> type of the value of the future
         */
        public static <T> void transferResult(final CompletionStage<T> source,
                                      final CompletableFuture<T> target) {
    source.whenCompleteAsync((result, throwable) -> {
        final boolean isSuccessful = throwable == null;
        if (isSuccessful) {
            target.complete(result);
        } else {
            target.completeExceptionally(throwable);
        }
    });
}
    }

Related

  1. sequence(List> futures)
  2. sequence(List> futures)
  3. submitTasks(ExecutorCompletionService ecs, Iterable> tasks)
  4. sumFutures(List> futures)
  5. transferResult(final CompletionStage source, final CompletableFuture target)
  6. unwrap(Throwable throwable, Class throwableA)
  7. waitFor(Future future)
  8. waitForAll(List> futures)
  9. waitForAll(List> res)