|
|
|
@ -21,6 +21,7 @@ import java.util.concurrent.CompletionStage; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeoutException; |
|
|
|
import java.util.concurrent.TimeoutException; |
|
|
|
|
|
|
|
import java.util.function.BiConsumer; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Adapts a {@link CompletableFuture} or {@link CompletionStage} into a |
|
|
|
* Adapts a {@link CompletableFuture} or {@link CompletionStage} into a |
|
|
|
@ -50,14 +51,13 @@ public class CompletableToListenableFutureAdapter<T> implements ListenableFuture |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) { |
|
|
|
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) { |
|
|
|
this.completableFuture = completableFuture; |
|
|
|
this.completableFuture = completableFuture; |
|
|
|
this.completableFuture.handle((result, ex) -> { |
|
|
|
this.completableFuture.whenComplete((result, ex) -> { |
|
|
|
if (ex != null) { |
|
|
|
if (ex != null) { |
|
|
|
callbacks.failure(ex); |
|
|
|
callbacks.failure(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
callbacks.success(result); |
|
|
|
callbacks.success(result); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|