Consistently support CompletionStage next to CompletableFuture
Issue: SPR-15258
(cherry picked from commit 50d93d3)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.util.concurrent;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -25,9 +26,11 @@ import java.util.function.BiFunction;
|
||||
import org.springframework.lang.UsesJava8;
|
||||
|
||||
/**
|
||||
* Adapts a {@link CompletableFuture} into a {@link ListenableFuture}.
|
||||
* Adapts a {@link CompletableFuture} or {@link CompletionStage} into a
|
||||
* Spring {@link ListenableFuture}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.2
|
||||
*/
|
||||
@UsesJava8
|
||||
@@ -38,6 +41,17 @@ public class CompletableToListenableFutureAdapter<T> implements ListenableFuture
|
||||
private final ListenableFutureCallbackRegistry<T> callbacks = new ListenableFutureCallbackRegistry<T>();
|
||||
|
||||
|
||||
/**
|
||||
* Create a new adapter for the given {@link CompletionStage}.
|
||||
* @since 4.3.7
|
||||
*/
|
||||
public CompletableToListenableFutureAdapter(CompletionStage<T> completionStage) {
|
||||
this(completionStage.toCompletableFuture());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new adapter for the given {@link CompletableFuture}.
|
||||
*/
|
||||
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) {
|
||||
this.completableFuture = completableFuture;
|
||||
this.completableFuture.handle(new BiFunction<T, Throwable, Object>() {
|
||||
|
||||
Reference in New Issue
Block a user