类 Futures
- java.lang.Object
-
- net.dongliu.commons.concurrent.Futures
-
public class Futures extends java.lang.ObjectUtils method for futures.
-
-
构造器概要
构造器 构造器 说明 Futures()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static <T> java.util.concurrent.CompletableFuture<java.util.List<T>>allOf(java.util.concurrent.CompletableFuture<T>... futures)Wait all future finished, and return a new Future hold the result.static <T> java.util.concurrent.CompletableFuture<T>anyOf(java.util.concurrent.CompletableFuture<T>... futures)Wait till any one finished, and return a new Future hold the result.static <A,B,C>
java.util.concurrent.CompletableFuture<Triple<A,B,C>>combine(java.util.concurrent.CompletableFuture<A> future1, java.util.concurrent.CompletableFuture<B> future2, java.util.concurrent.CompletableFuture<C> future3)Combine three futures to one future return a Triple Future.static <S,T>
java.util.concurrent.CompletableFuture<Pair<S,T>>combine(java.util.concurrent.CompletableFuture<S> future1, java.util.concurrent.CompletableFuture<T> future2)Combine two futures to one future return a Pair Future.static <T> java.util.concurrent.CompletableFuture<T>delay(java.util.concurrent.CompletableFuture<T> future, java.time.Duration duration)Create a new Future, which delay some time after the original future complete.static <T> java.util.concurrent.CompletableFuture<T>delay(T value, java.time.Duration duration)Create a new Future, which delay some time to complete.static <T> java.util.concurrent.CompletableFuture<T>error(java.lang.Throwable throwable)Alias for CompletableFuture.failedFuturestatic <T> Tjoin(java.util.concurrent.Future<T> future)Wait until future finished, and return the value.static <T> java.util.concurrent.CompletableFuture<T>just(T result)Alias for CompletableFuture.completedFuturestatic <T> java.util.concurrent.CompletableFuture<T>timeout(java.util.concurrent.CompletableFuture<T> future, java.time.Duration duration)Set timeout for wait future to complete.
-
-
-
方法详细资料
-
join
public static <T> T join(java.util.concurrent.Future<T> future)
Wait until future finished, and return the value. If error occurred, throw unchecked exception. If is interrupted, a CancellationException is thrown, and the interrupt bit is set for this thread.- 类型参数:
T- the future value type- 参数:
future- the future- 返回:
- the future value
- 抛出:
java.util.concurrent.CancellationException- if future is canceled, or get operation is interruptedjava.util.concurrent.CompletionException- if exception is thrown during future compute
-
just
public static <T> java.util.concurrent.CompletableFuture<T> just(T result)
Alias for CompletableFuture.completedFuture- 类型参数:
T- the value type- 参数:
result- the value- 返回:
- the completed CompletableFuture
-
error
public static <T> java.util.concurrent.CompletableFuture<T> error(java.lang.Throwable throwable)
Alias for CompletableFuture.failedFuture- 类型参数:
T- the value type- 参数:
throwable- the throwable- 返回:
- the failed CompletableFuture
-
delay
public static <T> java.util.concurrent.CompletableFuture<T> delay(java.util.concurrent.CompletableFuture<T> future, java.time.Duration duration)Create a new Future, which delay some time after the original future complete. If the original future failed, delay is not added.- 类型参数:
T- value type- 参数:
future- the original futureduration- delay time- 返回:
- the new future with delay
-
delay
public static <T> java.util.concurrent.CompletableFuture<T> delay(T value, java.time.Duration duration)Create a new Future, which delay some time to complete.- 类型参数:
T- value type- 参数:
value- the futureduration- delay time- 返回:
- the new future with delay
-
timeout
public static <T> java.util.concurrent.CompletableFuture<T> timeout(java.util.concurrent.CompletableFuture<T> future, java.time.Duration duration)Set timeout for wait future to complete. Throw TimeoutException if not complete when timeout reached. Java9+ CompletableFuture already has this method.- 类型参数:
T- value type- 参数:
future- the original futureduration- timeout time- 返回:
- the new future with timeout
-
allOf
@SafeVarargs public static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> allOf(java.util.concurrent.CompletableFuture<T>... futures)
Wait all future finished, and return a new Future hold the result. If any future failed, the new future failed.- 类型参数:
T- the value type of future- 参数:
futures- the futures- 返回:
- new future
-
anyOf
@SafeVarargs public static <T> java.util.concurrent.CompletableFuture<T> anyOf(java.util.concurrent.CompletableFuture<T>... futures)
Wait till any one finished, and return a new Future hold the result. If the finished future failed, the new future failed.- 类型参数:
T- the value type of future- 参数:
futures- the futures- 返回:
- new future
-
combine
public static <S,T> java.util.concurrent.CompletableFuture<Pair<S,T>> combine(java.util.concurrent.CompletableFuture<S> future1, java.util.concurrent.CompletableFuture<T> future2)
Combine two futures to one future return a Pair Future. If either future failed with a exception, the return future failed.
-
combine
public static <A,B,C> java.util.concurrent.CompletableFuture<Triple<A,B,C>> combine(java.util.concurrent.CompletableFuture<A> future1, java.util.concurrent.CompletableFuture<B> future2, java.util.concurrent.CompletableFuture<C> future3)
Combine three futures to one future return a Triple Future. If either future failed with a exception, the return future failed.
-
-