public class AsyncUtil extends Object
Futures. Many of the methods
in this class have two versions -- one for dealing with PartialFutures and
one for Futures.| Modifier and Type | Method and Description |
|---|---|
static <I,O> Future<O> |
applySafely(Function<I,Future<O>> func,
I value)
Run
Function func, returning all caught exceptions as a
Future in an error state. |
static <I,O> PartialFuture<O> |
applySafely(PartialFunction<I,? extends PartialFuture<O>> func,
I value)
Run
PartialFunction func, returning all caught exceptions as a
PartialFuture in an error state. |
static <V> Future<List<V>> |
collect(AsyncIterable<V> iterable)
Iterates over a set of items and returns the result as a list.
|
static <V> Future<List<V>> |
getAll(Collection<Future<V>> tasks)
Collects the results of many asynchronous processes into one asynchronous output.
|
static <V> PartialFuture<List<V>> |
getAllPartial(Collection<PartialFuture<V>> tasks)
Collects the results of many asynchronous processes into one asynchronous output.
|
static <V,T> AsyncIterable<T> |
mapIterable(AsyncIterable<V> iterable,
Function<V,T> func)
Map an
AsyncIterable into an AsyncIterable of another type or with
each element modified in some fashion. |
static <V> Future<Void> |
success(Future<V> task)
Maps the outcome of a task into a completion signal.
|
static <V> PartialFuture<Void> |
success(PartialFuture<V> task)
Maps the outcome of a task into a completion signal.
|
static <V,T> Future<V> |
tag(Future<T> task,
V value)
Replaces the output of an asynchronous task with a predetermined value.
|
static <V,T> PartialFuture<V> |
tag(PartialFuture<T> task,
V value)
Replaces the output of an asynchronous task with a predetermined value.
|
static <V> Future<Void> |
whenAll(Collection<? extends PartialFuture<V>> input)
Return a
Future that will be set when all the PartialFuture
inputs are done. |
static <V> Future<Void> |
whenAny(Collection<? extends PartialFuture<V>> input)
Return a
Future that will be set when any of the PartialFuture
inputs are done. |
static <V> Future<Void> |
whenReady(PartialFuture<V> task)
Maps the readiness of a
PartialFuture into a completion signal. |
static Future<Void> |
whileTrue(Function<Void,Future<Boolean>> body)
Executes an asynchronous operation repeatedly until it returns
False. |
static PartialFuture<Void> |
whileTrue(PartialFunction<Void,? extends PartialFuture<Boolean>> body)
Executes an asynchronous operation repeatedly until it returns
False. |
public static <I,O> Future<O> applySafely(Function<I,Future<O>> func, I value)
Function func, returning all caught exceptions as a
Future in an error state.func - the Function to runvalue - the input to pass to funcfunc, or a Future carrying any exception
caught in the process.public static <I,O> PartialFuture<O> applySafely(PartialFunction<I,? extends PartialFuture<O>> func, I value)
PartialFunction func, returning all caught exceptions as a
PartialFuture in an error state.func - the PartialFunction to runvalue - the input to pass to funcfunc, or a PartialFuture carrying any exception
caught in the process.public static <V> Future<List<V>> collect(AsyncIterable<V> iterable)
iterable - the source of data over which to iterateFuture which will be set to the amalgamation of results
from iteration.public static <V,T> AsyncIterable<T> mapIterable(AsyncIterable<V> iterable, Function<V,T> func)
AsyncIterable into an AsyncIterable of another type or with
each element modified in some fashion.iterable - inputfunc - mapping function applied to each elementpublic static PartialFuture<Void> whileTrue(PartialFunction<Void,? extends PartialFuture<Boolean>> body)
False.body - the asynchronous operation over which to loopPartialFuture which will be set at completion of the loop.public static Future<Void> whileTrue(Function<Void,Future<Boolean>> body)
False.body - the asynchronous operation over which to loopFuture which will be set at completion of the loop.public static <V> Future<Void> success(Future<V> task)
task has
side-effects for which all is needed is a signal of completion.
All errors from task will be passed to the resulting Future.task - the asynchronous process for which to signal completionFuture that is set when task completespublic static <V> PartialFuture<Void> success(PartialFuture<V> task)
task has
side-effects for which all is needed is a signal of completion.
All errors from task will be passed to the resulting PartialFuture.task - the asynchronous process for which to signal completionFuture that is set when task completespublic static <V> Future<Void> whenReady(PartialFuture<V> task)
PartialFuture into a completion signal. When
the given PartialFuture is set to a value or an error, the returned Future
will be set to null. The returned Future will never be set to an error unless
it is explicitly cancelled.task - the asynchronous process to monitor the readiness ofFuture that is set when task is ready.public static <V> Future<List<V>> getAll(Collection<Future<V>> tasks)
tasks - the tasks whose output is to be added to the outputFuture that will be set to the collective result of the taskspublic static <V> PartialFuture<List<V>> getAllPartial(Collection<PartialFuture<V>> tasks)
tasks - the tasks whose output is to be added to the outputFuture that will be set to the collective result of the taskspublic static <V,T> Future<V> tag(Future<T> task, V value)
task - the asynchronous process whose output is to be replacedvalue - the predetermined value to be returned on success of taskFuture that will be set to value on completion of taskpublic static <V,T> PartialFuture<V> tag(PartialFuture<T> task, V value)
task - the asynchronous process whose output is to be replacedvalue - the predetermined value to be returned on success of taskFuture that will be set to value on completion of taskpublic static <V> Future<Void> whenAny(Collection<? extends PartialFuture<V>> input)
Future that will be set when any of the PartialFuture
inputs are done. A Future is done both on success and failure.input - the list of PartialFutures to monitor. This list
must not be modified during the execution of this call.Futures are donepublic static <V> Future<Void> whenAll(Collection<? extends PartialFuture<V>> input)
Future that will be set when all the PartialFuture
inputs are done. A Future is done both on success and failure.input - the list of PartialFutures to monitor. This list
must not be modified during the execution of this call.Futures are done