Here you can find the source of transferResult(final CompletionStage
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 |
public static <T> void transferResult(final CompletionStage<T> source, final CompletableFuture<T> target)
//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); } }); } }