Class FutureUtils
- java.lang.Object
-
- org.threadly.concurrent.future.FutureUtils
-
public class FutureUtils extends java.lang.Object
A collection of small utilities for handling futures. This class has lots of tools for dealing with collections of futures, ranging from blocking, extracting results, and more.Generating already done futures:
Tools for blocking:
blockTillAllComplete(Iterable)
blockTillAllComplete(Iterable, long)
blockTillAllCompleteOrFirstError(Iterable)
blockTillAllCompleteOrFirstError(Iterable, long)
Tools for manipulating collections of futures:
cancelIncompleteFutures(Iterable, boolean)
cancelIncompleteFuturesIfAnyFail(boolean, Iterable, boolean)
countFuturesWithResult(Iterable, Object)
countFuturesWithResult(Iterable, Object, long)
invokeAfterAllComplete(Collection, Runnable)
invokeAfterAllComplete(Collection, Runnable, Executor)
makeFirstResultFuture(Collection, boolean)
makeFirstResultFuture(Collection, boolean, boolean)
makeCompleteFuture(Iterable)
makeCompleteFuture(Iterable, Object)
makeFailurePropagatingCompleteFuture(Iterable)
makeFailurePropagatingCompleteFuture(Iterable, Object)
makeCompleteListFuture(Iterable)
makeFailureListFuture(Iterable)
makeResultListFuture(Iterable, boolean)
makeSuccessListFuture(Iterable)
Retry operation and return final result in future:
scheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate)
scheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate, long, boolean)
scheduleWhile(SubmitterScheduler, long, ListenableFuture, Callable, Predicate)
scheduleWhile(SubmitterScheduler, long, ListenableFuture, Callable, Predicate, long, boolean)
scheduleWhile(SubmitterScheduler, long, boolean, Runnable, Supplier)
scheduleWhile(SubmitterScheduler, long, boolean, Runnable, Supplier, long)
executeWhile(Callable, Predicate)
executeWhile(Callable, Predicate, long, boolean)
executeWhile(ListenableFuture, Callable, Predicate)
executeWhile(ListenableFuture, Callable, Predicate, long, boolean)
- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor Description FutureUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
blockTillAllComplete(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures)
This call blocks till all futures in the list have completed.static void
blockTillAllComplete(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, long timeoutInMillis)
This call blocks till all futures in the list have completed.static void
blockTillAllComplete(java.util.concurrent.Future<?>... futures)
This call blocks till all futures in the list have completed.static void
blockTillAllCompleteOrFirstError(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures)
This call blocks till all futures in the list have completed.static void
blockTillAllCompleteOrFirstError(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, long timeoutInMillis)
This call blocks till all futures in the list have completed.static void
blockTillAllCompleteOrFirstError(java.util.concurrent.Future<?>... futures)
This call blocks till all futures in the list have completed.static void
cancelIncompleteFutures(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, boolean interruptThread)
InvokedFuture.cancel(boolean)
for every future in this collection.static void
cancelIncompleteFuturesIfAnyFail(boolean copy, java.lang.Iterable<? extends ListenableFuture<?>> futures, boolean interruptThread)
Provide a group of futures and cancel all of them if any of them are canceled or fail.static <T> int
countFuturesWithResult(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, T comparisonResult)
Counts how many futures provided completed with a result that matches the one provided here.static <T> int
countFuturesWithResult(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, T comparisonResult, long timeoutInMillis)
Counts how many futures provided completed with a result that matches the one provided here.static <T> ListenableFuture<T>
executeWhile(java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest)
Similar toscheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).static <T> ListenableFuture<T>
executeWhile(java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean timeoutProvideLastValue)
Similar toscheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate, long, boolean)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).static <T> ListenableFuture<T>
executeWhile(ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest)
Similar toscheduleWhile(SubmitterScheduler, long, ListenableFuture, Callable, Predicate)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).static <T> ListenableFuture<T>
executeWhile(ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean lastValueOnTimeout)
Similar toscheduleWhile(SubmitterScheduler, long, ListenableFuture, Callable, Predicate, long, boolean)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).static <T> ListenableFuture<T>
immediateFailureFuture(java.lang.Throwable failure)
Constructs aListenableFuture
that has failed with the given failure.static <T> ListenableFuture<T>
immediateResultFuture(T result)
Constructs aListenableFuture
that has already had the provided result given to it.static void
invokeAfterAllComplete(java.util.Collection<? extends ListenableFuture<?>> futures, java.lang.Runnable listener)
A potentially more performant option thanmakeCompleteFuture(List)
when only a listener invocation is desired after all the futures complete.static void
invokeAfterAllComplete(java.util.Collection<? extends ListenableFuture<?>> futures, java.lang.Runnable listener, java.util.concurrent.Executor executor)
A potentially more performant option thanmakeCompleteFuture(List)
when only a listener invocation is desired after all the futures complete.static ListenableFuture<?>
makeCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking.static <T> ListenableFuture<T>
makeCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures, T result)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking.static ListenableFuture<?>
makeCompleteFuture(java.util.Collection<? extends ListenableFuture<?>> futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking.static ListenableFuture<?>
makeCompleteFuture(java.util.List<? extends ListenableFuture<?>> futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking.static ListenableFuture<?>
makeCompleteFuture(ListenableFuture<?>... futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking.static <T> ListenableFuture<java.util.List<ListenableFuture<? extends T>>>
makeCompleteListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures)
This call is similar tomakeCompleteFuture(Iterable)
in that it will immediately provide a future that will not be satisfied till all provided futures complete.static <T> ListenableFuture<java.util.List<ListenableFuture<? extends T>>>
makeFailureListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures)
This call is similar tomakeCompleteFuture(Iterable)
in that it will immediately provide a future that will not be satisfied till all provided futures complete.static ListenableFuture<?>
makeFailurePropagatingCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures)
Similar tomakeCompleteFuture(Iterable)
in that the returned future wont complete until all the provided futures complete.static <T> ListenableFuture<T>
makeFailurePropagatingCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures, T result)
Similar tomakeCompleteFuture(Iterable, Object)
in that the returned future wont complete until all the provided futures complete.static ListenableFuture<?>
makeFailurePropagatingCompleteFuture(ListenableFuture<?>... futures)
Similar tomakeCompleteFuture(Iterable)
in that the returned future wont complete until all the provided futures complete.static <T> ListenableFuture<T>
makeFirstResultFuture(java.util.Collection<? extends ListenableFuture<? extends T>> c, boolean ignoreErrors)
Converts a collection ofListenableFuture
's into a singleListenableFuture
where the result will be the first result provided from the collection.static <T> ListenableFuture<T>
makeFirstResultFuture(java.util.Collection<? extends ListenableFuture<? extends T>> c, boolean ignoreErrors, boolean interruptOnCancel)
Converts a collection ofListenableFuture
's into a singleListenableFuture
where the result will be the first result provided from the collection.static <T> ListenableFuture<java.util.List<T>>
makeResultListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures, boolean ignoreFailedFutures)
This returns a future which provides the results of all the provided futures.static <T> ListenableFuture<java.util.List<ListenableFuture<? extends T>>>
makeSuccessListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures)
This call is similar tomakeCompleteFuture(Iterable)
in that it will immediately provide a future that will not be satisfied till all provided futures complete.static ListenableFuture<?>
scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.lang.Runnable task, java.util.function.Supplier<java.lang.Boolean> loopTest)
Executes a task until the provided supplier returnsfalse
.static ListenableFuture<?>
scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.lang.Runnable task, java.util.function.Supplier<java.lang.Boolean> loopTest, long timeoutMillis)
Executes a task, checking the result from the task to see if it needs to reschedule the task again.static <T> ListenableFuture<T>
scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest)
Executes a task, checking the result from the task to see if it needs to reschedule the task again.static <T> ListenableFuture<T>
scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean timeoutProvideLastValue)
Executes a task, checking the result from the task to see if it needs to reschedule the task again.static <T> ListenableFuture<T>
scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest)
Executes a task, checking the result from the task to see if it needs to reschedule the task again.static <T> ListenableFuture<T>
scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean timeoutProvideLastValue)
Executes a task, checking the result from the task to see if it needs to reschedule the task again.
-
-
-
Method Detail
-
blockTillAllComplete
public static void blockTillAllComplete(java.util.concurrent.Future<?>... futures) throws java.lang.InterruptedException
This call blocks till all futures in the list have completed. If the future completed with an error, theExecutionException
is swallowed. Meaning that this does not attempt to verify that all futures completed successfully. If you need to know if any failed, please useblockTillAllCompleteOrFirstError(Iterable)
.If you need to specify a timeout to control how long to block, consider using
blockTillAllComplete(Iterable, long)
.- Parameters:
futures
- Futures to block till they complete- Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on future
-
blockTillAllComplete
public static void blockTillAllComplete(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures) throws java.lang.InterruptedException
This call blocks till all futures in the list have completed. If the future completed with an error, theExecutionException
is swallowed. Meaning that this does not attempt to verify that all futures completed successfully. If you need to know if any failed, please useblockTillAllCompleteOrFirstError(Iterable)
.If you need to specify a timeout to control how long to block, consider using
blockTillAllComplete(Iterable, long)
.- Parameters:
futures
- Structure of futures to iterate over- Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on future
-
blockTillAllComplete
public static void blockTillAllComplete(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, long timeoutInMillis) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
This call blocks till all futures in the list have completed. If the future completed with an error, theExecutionException
is swallowed. Meaning that this does not attempt to verify that all futures completed successfully. If you need to know if any failed, please useblockTillAllCompleteOrFirstError(Iterable, long)
.- Parameters:
futures
- Structure of futures to iterate overtimeoutInMillis
- timeout to wait for futures to complete in milliseconds- Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on futurejava.util.concurrent.TimeoutException
- Thrown if the timeout elapsed while waiting on futures to complete- Since:
- 4.0.0
-
blockTillAllCompleteOrFirstError
public static void blockTillAllCompleteOrFirstError(java.util.concurrent.Future<?>... futures) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
This call blocks till all futures in the list have completed. If the future completed with an error anExecutionException
is thrown. If this exception is thrown, all futures may or may not be completed, the exception is thrown as soon as it is hit. There also may be additional futures that errored (but were not hit yet).If you need to specify a timeout to control how long to block, consider using
blockTillAllCompleteOrFirstError(Iterable, long)
.- Parameters:
futures
- Futures to iterate over- Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on futurejava.util.concurrent.ExecutionException
- Thrown if future throws exception on .get() call
-
blockTillAllCompleteOrFirstError
public static void blockTillAllCompleteOrFirstError(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
This call blocks till all futures in the list have completed. If the future completed with an error anExecutionException
is thrown. If this exception is thrown, all futures may or may not be completed, the exception is thrown as soon as it is hit. There also may be additional futures that errored (but were not hit yet).If you need to specify a timeout to control how long to block, consider using
blockTillAllCompleteOrFirstError(Iterable, long)
.- Parameters:
futures
- Structure of futures to iterate over- Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on futurejava.util.concurrent.ExecutionException
- Thrown if future throws exception on .get() call
-
blockTillAllCompleteOrFirstError
public static void blockTillAllCompleteOrFirstError(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, long timeoutInMillis) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException, java.util.concurrent.ExecutionException
This call blocks till all futures in the list have completed. If the future completed with an error anExecutionException
is thrown. If this exception is thrown, all futures may or may not be completed, the exception is thrown as soon as it is hit. There also may be additional futures that errored (but were not hit yet).- Parameters:
futures
- Structure of futures to iterate overtimeoutInMillis
- timeout to wait for futures to complete in milliseconds- Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on futurejava.util.concurrent.TimeoutException
- Thrown if the timeout elapsed while waiting on futures to completejava.util.concurrent.ExecutionException
- Thrown if future throws exception on .get() call- Since:
- 4.0.0
-
countFuturesWithResult
public static <T> int countFuturesWithResult(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, T comparisonResult) throws java.lang.InterruptedException
Counts how many futures provided completed with a result that matches the one provided here. This can be most useful if your looking to know if an error occurred that was not anExecutionException
. For example assume an API return'sFuture<Boolean>
and afalse
represents a failure, this can be used to look for those types of error results.Just like
blockTillAllComplete(Iterable)
, this will block until all futures have completed (so we can verify if their result matches or not).If you need to specify a timeout to control how long to block, consider using
countFuturesWithResult(Iterable, Object, long)
.- Type Parameters:
T
- type of result futures provide to compare against- Parameters:
futures
- Structure of futures to iterate overcomparisonResult
- Object to compare future results against to look for match- Returns:
- Number of futures which match the result using a
Object.equals(Object)
comparison - Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on future's result- Since:
- 4.0.0
-
countFuturesWithResult
public static <T> int countFuturesWithResult(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, T comparisonResult, long timeoutInMillis) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
Counts how many futures provided completed with a result that matches the one provided here. This can be most useful if your looking to know if an error occurred that was not anExecutionException
. For example assume an API return'sFuture<Boolean>
and afalse
represents a failure, this can be used to look for those types of error results.Just like
blockTillAllComplete(Iterable)
, this will block until all futures have completed (so we can verify if their result matches or not).- Type Parameters:
T
- type of result futures provide to compare against- Parameters:
futures
- Structure of futures to iterate overcomparisonResult
- Object to compare future results against to look for matchtimeoutInMillis
- timeout to wait for futures to complete in milliseconds- Returns:
- Number of futures which match the result using a
Object.equals(Object)
comparison - Throws:
java.lang.InterruptedException
- Thrown if thread is interrupted while waiting on future's resultjava.util.concurrent.TimeoutException
- Thrown if the timeout elapsed while waiting on futures to complete- Since:
- 4.0.0
-
invokeAfterAllComplete
public static void invokeAfterAllComplete(java.util.Collection<? extends ListenableFuture<?>> futures, java.lang.Runnable listener)
A potentially more performant option thanmakeCompleteFuture(List)
when only a listener invocation is desired after all the futures complete. This is effective an async implementation ofblockTillAllComplete(Iterable)
. If the listener needs to be invoked on another thread than one of the provided futures please useinvokeAfterAllComplete(Collection, Runnable, Executor)
. Please seeListenableFuture.listener(Runnable)
for more information on execution without anExecutor
.It is critical that the collection is NOT modified while this is invoked. A change in the futures contained in the collection will lead to unreliable behavior with the exectuion of the listener.
- Parameters:
futures
- Futures that must complete before listener is invokedlistener
- Invoked once all the provided futures have completed
-
invokeAfterAllComplete
public static void invokeAfterAllComplete(java.util.Collection<? extends ListenableFuture<?>> futures, java.lang.Runnable listener, java.util.concurrent.Executor executor)
A potentially more performant option thanmakeCompleteFuture(List)
when only a listener invocation is desired after all the futures complete. This is effective an async implementation ofblockTillAllComplete(Iterable)
.It is critical that the collection is NOT modified while this is invoked. A change in the futures contained in the collection will lead to unreliable behavior with the exectuion of the listener.
- Parameters:
futures
- Futures that must complete before listener is invokedlistener
- Invoked once all the provided futures have completedexecutor
- Executor (ornull
) to invoke listener on, seeListenableFuture.listener(Runnable, Executor)
-
makeFirstResultFuture
public static <T> ListenableFuture<T> makeFirstResultFuture(java.util.Collection<? extends ListenableFuture<? extends T>> c, boolean ignoreErrors)
Converts a collection ofListenableFuture
's into a singleListenableFuture
where the result will be the first result provided from the collection.If
ignoreErrors
isfalse
the returned future will complete as soon as the first future completes, if it completes in error then the error would be returned. IfignoreErrors
istrue
then the returned future will complete once a result is provided, or once all futures have completed in error. If all futures did complete in error then the last error state will be specified to the resultingListenableFuture
. This minor bookkeeping to ignore errors does incur a slight overhead.- Type Parameters:
T
- type of result provided in the returned future- Parameters:
c
- Collection of futures to monitor for resultignoreErrors
-false
to communicate the first completed future state, even if in error- Returns:
- A future which will be provided the first result from any in the provided
Collection
- Since:
- 6.6
-
makeFirstResultFuture
public static <T> ListenableFuture<T> makeFirstResultFuture(java.util.Collection<? extends ListenableFuture<? extends T>> c, boolean ignoreErrors, boolean interruptOnCancel)
Converts a collection ofListenableFuture
's into a singleListenableFuture
where the result will be the first result provided from the collection.If
ignoreErrors
isfalse
the returned future will complete as soon as the first future completes, if it completes in error then the error would be returned. IfignoreErrors
istrue
then the returned future will complete once a result is provided, or once all futures have completed in error. If all futures did complete in error then the last error state will be specified to the resultingListenableFuture
. This minor bookkeeping to ignore errors does incur a slight overhead.It is expected that the first result is the only result desired, once it is found this will attempt to cancel all remaining futures. If you may want other results which were in progress, then specifying
interruptOnCancel
asfalse
will mean that any futures which started can complete. You can then inspect the collection for done futures which might have a result. If there is no concern for other results, then you likely will want to interrupt started futures.- Type Parameters:
T
- type of result provided in the returned future- Parameters:
c
- Collection of futures to monitor for resultignoreErrors
-false
to communicate the first completed future state, even if in errorinterruptOnCancel
-true
to send a interrupt on any running futures after we have a result- Returns:
- A future which will be provided the first result from any in the provided
Collection
- Since:
- 5.38
-
makeCompleteFuture
public static ListenableFuture<?> makeCompleteFuture(java.util.List<? extends ListenableFuture<?>> futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking. UnlikeblockTillAllComplete(Iterable)
, this requires that you provide a collection ofListenableFuture
's. But will return immediately, providing a newListenableFuture
that will be called once all the provided futures have finished.The future returned will provide a
null
result, it is the responsibility of the caller to get the actual results from the provided futures. This is designed to just be an indicator as to when they have finished. If you need the results from the provided futures, consider usingmakeCompleteListFuture(Iterable)
. You should also consider usingmakeFailurePropagatingCompleteFuture(Iterable)
, it has the same semantics as this one except it will put the returned future into an error state if any of the provided futures error.- Parameters:
futures
- Collection of futures that must finish before returned future is satisfied- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 5.3
-
makeCompleteFuture
public static ListenableFuture<?> makeCompleteFuture(java.util.Collection<? extends ListenableFuture<?>> futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking. UnlikeblockTillAllComplete(Iterable)
, this requires that you provide a collection ofListenableFuture
's. But will return immediately, providing a newListenableFuture
that will be called once all the provided futures have finished.The future returned will provide a
null
result, it is the responsibility of the caller to get the actual results from the provided futures. This is designed to just be an indicator as to when they have finished. If you need the results from the provided futures, consider usingmakeCompleteListFuture(Iterable)
. You should also consider usingmakeFailurePropagatingCompleteFuture(Iterable)
, it has the same semantics as this one except it will put the returned future into an error state if any of the provided futures error.- Parameters:
futures
- Collection of futures that must finish before returned future is satisfied- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 5.3
-
makeCompleteFuture
public static ListenableFuture<?> makeCompleteFuture(ListenableFuture<?>... futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking. UnlikeblockTillAllComplete(Iterable)
, this requires that you provide a collection ofListenableFuture
's. But will return immediately, providing a newListenableFuture
that will be called once all the provided futures have finished.The future returned will provide a
null
result, it is the responsibility of the caller to get the actual results from the provided futures. This is designed to just be an indicator as to when they have finished. If you need the results from the provided futures, consider usingmakeCompleteListFuture(Iterable)
. You should also consider usingmakeFailurePropagatingCompleteFuture(Iterable)
, it has the same semantics as this one except it will put the returned future into an error state if any of the provided futures error.- Parameters:
futures
- Futures that must finish before returned future is satisfied- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 1.2.0
-
makeCompleteFuture
public static ListenableFuture<?> makeCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking. UnlikeblockTillAllComplete(Iterable)
, this requires that you provide a collection ofListenableFuture
's. But will return immediately, providing a newListenableFuture
that will be called once all the provided futures have finished.The future returned will provide a
null
result, it is the responsibility of the caller to get the actual results from the provided futures. This is designed to just be an indicator as to when they have finished. If you need the results from the provided futures, consider usingmakeCompleteListFuture(Iterable)
. You should also consider usingmakeFailurePropagatingCompleteFuture(Iterable)
, it has the same semantics as this one except it will put the returned future into an error state if any of the provided futures error.- Parameters:
futures
- Collection of futures that must finish before returned future is satisfied- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 1.2.0
-
makeCompleteFuture
public static <T> ListenableFuture<T> makeCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures, T result)
An alternative toblockTillAllComplete(Iterable)
, this provides the ability to know when all futures are complete without blocking. UnlikeblockTillAllComplete(Iterable)
, this requires that you provide a collection ofListenableFuture
's. But will return immediately, providing a newListenableFuture
that will be called once all the provided futures have finished.The future returned will provide the result object once all provided futures have completed. If any failures occured, they will not be represented in the returned future. If that is desired you should consider using
makeFailurePropagatingCompleteFuture(Iterable, Object)
, it has the same semantics as this one except it will put the returned future into an error state if any of the provided futures error.- Type Parameters:
T
- type of result returned from the future- Parameters:
futures
- Collection of futures that must finish before returned future is satisfiedresult
- Result to provide returned future once all futures complete- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 3.3.0
-
makeFailurePropagatingCompleteFuture
public static ListenableFuture<?> makeFailurePropagatingCompleteFuture(ListenableFuture<?>... futures)
Similar tomakeCompleteFuture(Iterable)
in that the returned future wont complete until all the provided futures complete. However this implementation will check if any futures failed or were canceled once all have completed. If any did not complete normally then the returned futures state will match the state of one of the futures that did not normally (randomly chosen).Since the returned future wont complete until all futures complete, you may want to consider using
cancelIncompleteFuturesIfAnyFail(boolean, Iterable, boolean)
in addition to this so that the future will resolve as soon as any failures occur.- Parameters:
futures
- Collection of futures that must finish before returned future is satisfied- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 5.0
-
makeFailurePropagatingCompleteFuture
public static ListenableFuture<?> makeFailurePropagatingCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures)
Similar tomakeCompleteFuture(Iterable)
in that the returned future wont complete until all the provided futures complete. However this implementation will check if any futures failed or were canceled once all have completed. If any did not complete normally then the returned futures state will match the state of one of the futures that did not normally (randomly chosen).Since the returned future wont complete until all futures complete, you may want to consider using
cancelIncompleteFuturesIfAnyFail(boolean, Iterable, boolean)
in addition to this so that the future will resolve as soon as any failures occur.- Parameters:
futures
- Collection of futures that must finish before returned future is satisfied- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 5.0
-
makeFailurePropagatingCompleteFuture
public static <T> ListenableFuture<T> makeFailurePropagatingCompleteFuture(java.lang.Iterable<? extends ListenableFuture<?>> futures, T result)
Similar tomakeCompleteFuture(Iterable, Object)
in that the returned future wont complete until all the provided futures complete. However this implementation will check if any futures failed or were canceled once all have completed. If any did not complete normally then the returned futures state will match the state of one of the futures that did not normally (randomly chosen).Since the returned future wont complete until all futures complete, you may want to consider using
cancelIncompleteFuturesIfAnyFail(boolean, Iterable, boolean)
in addition to this so that the future will resolve as soon as any failures occur.- Type Parameters:
T
- type of result returned from the future- Parameters:
futures
- Collection of futures that must finish before returned future is satisfiedresult
- Result to provide returned future once all futures complete- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 5.0
-
makeCompleteListFuture
public static <T> ListenableFuture<java.util.List<ListenableFuture<? extends T>>> makeCompleteListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures)
This call is similar tomakeCompleteFuture(Iterable)
in that it will immediately provide a future that will not be satisfied till all provided futures complete.This future provides a list of the completed futures as the result. The order of the result list will match the order returned by the provided
Iterable
.If
Future.cancel(boolean)
is invoked on the returned future, all provided futures will attempt to be canceled in the same way.- Type Parameters:
T
- The result object type returned from the futures- Parameters:
futures
- Structure of futures to iterate over- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 1.2.0
-
makeSuccessListFuture
public static <T> ListenableFuture<java.util.List<ListenableFuture<? extends T>>> makeSuccessListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures)
This call is similar tomakeCompleteFuture(Iterable)
in that it will immediately provide a future that will not be satisfied till all provided futures complete.This future provides a list of the futures that completed without throwing an exception nor were canceled. The order of the resulting list is NOT deterministic. If order is needed please see
makeCompleteListFuture(Iterable)
and check for results.If
Future.cancel(boolean)
is invoked on the returned future, all provided futures will attempt to be canceled in the same way.- Type Parameters:
T
- The result object type returned from the futures- Parameters:
futures
- Structure of futures to iterate over- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 1.2.0
-
makeFailureListFuture
public static <T> ListenableFuture<java.util.List<ListenableFuture<? extends T>>> makeFailureListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures)
This call is similar tomakeCompleteFuture(Iterable)
in that it will immediately provide a future that will not be satisfied till all provided futures complete.This future provides a list of the futures that failed by either throwing an exception or were canceled. The order of the resulting list is NOT deterministic. If order is needed please see
makeCompleteListFuture(Iterable)
and check for results.If
Future.cancel(boolean)
is invoked on the returned future, all provided futures will attempt to be canceled in the same way.- Type Parameters:
T
- The result object type returned from the futures- Parameters:
futures
- Structure of futures to iterate over- Returns:
- ListenableFuture which will be done once all futures provided are done
- Since:
- 1.2.0
-
makeResultListFuture
public static <T> ListenableFuture<java.util.List<T>> makeResultListFuture(java.lang.Iterable<? extends ListenableFuture<? extends T>> futures, boolean ignoreFailedFutures)
This returns a future which provides the results of all the provided futures. Thus preventing the need to iterate over all the futures and manually extract the results. This call does NOT block, instead it will return a future which will not complete until all the provided futures complete.The order of the result list will match the order returned by the provided
Iterable
.If called with
true
forignoreFailedFutures
, even if some of the provided futures finished in error, they will be ignored and just the successful results will be provided. If called withfalse
then if any futures complete in error, then the returned future will throw aExecutionException
with the error as the cause whenFuture.get()
is invoked. In addition if called withfalse
and any of the provided futures are canceled, then the returned future will also be canceled, resulting in aCancellationException
being thrown whenFuture.get()
is invoked. In the case where there is canceled and failed exceptions in the collection, this will prefer to throw the failure as anExecutionException
rather than obscure it with aCancellationException
. In other wordsCancellationException
will be thrown ONLY if there was canceled tasks, but NO tasks which finished in error.- Type Parameters:
T
- The result object type returned from the futures- Parameters:
futures
- Structure of futures to iterate over and extract results fromignoreFailedFutures
-true
to ignore any failed or canceled futures- Returns:
- A
ListenableFuture
which will provide a list of the results from the provided futures - Since:
- 4.0.0
-
cancelIncompleteFutures
public static void cancelIncompleteFutures(java.lang.Iterable<? extends java.util.concurrent.Future<?>> futures, boolean interruptThread)
InvokedFuture.cancel(boolean)
for every future in this collection. Thus if there are any futures which have not already completed, they will now be marked as canceled.- Parameters:
futures
- Collection of futures to iterate through and cancelinterruptThread
- Valued passed in to interrupt thread when callingFuture.cancel(boolean)
-
cancelIncompleteFuturesIfAnyFail
public static void cancelIncompleteFuturesIfAnyFail(boolean copy, java.lang.Iterable<? extends ListenableFuture<?>> futures, boolean interruptThread)
Provide a group of futures and cancel all of them if any of them are canceled or fail.If
false
is provided forcopy
parameter, thenfutures
will be iterated over twice, once during this invocation, and again when needing to cancel the futures. Because of that it is critical theIterable
provided returns the exact same future contents at the time of invoking this call. If that guarantee can not be provided, you must specifytrue
for thecopy
parameter.- Parameters:
copy
-true
to copy provided futures to avoidfutures
- Futures to be monitored and canceled on errorinterruptThread
- Valued passed in to interrupt thread when callingFuture.cancel(boolean)
- Since:
- 4.7.2
-
immediateResultFuture
public static <T> ListenableFuture<T> immediateResultFuture(T result)
Constructs aListenableFuture
that has already had the provided result given to it. Thus the resulting future can not error, block, or be canceled.If
null
is provided here the static instance ofImmediateResultListenableFuture.NULL_RESULT
will be returned to reduce GC overhead. This function may additionally try to optimize the references to other common cases (likeBoolean
results) when performance permits it. Those de-duplications may change based off benchmarking results, so be careful about depending on them. If no de-duplication is desired (ie the Future is used as a key in aMap
), then manually construct a newImmediateResultListenableFuture
.- Type Parameters:
T
- The result object type returned by the returned future- Parameters:
result
- result to be provided in .get() call- Returns:
- Already satisfied future
- Since:
- 1.2.0
-
immediateFailureFuture
public static <T> ListenableFuture<T> immediateFailureFuture(java.lang.Throwable failure)
Constructs aListenableFuture
that has failed with the given failure. Thus the resulting future can not block, or be canceled. Calls toFuture.get()
will immediately throw anExecutionException
.- Type Parameters:
T
- The result object type returned by the returned future- Parameters:
failure
- to provide as cause for ExecutionException thrown from .get() call- Returns:
- Already satisfied future
- Since:
- 1.2.0
-
scheduleWhile
public static ListenableFuture<?> scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.lang.Runnable task, java.util.function.Supplier<java.lang.Boolean> loopTest)
Executes a task until the provided supplier returnsfalse
. This can be a good way to implement retry logic where there completion (but not result) needs to be communicated. If a result is needed please seescheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate)
.The returned future will only provide a result once the looping of the task has completed. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.
The first execution will either be immediately executed in thread or submitted for immediate execution on the provided scheduler (depending on
firstRunAsync
parameter). Once this execution completes the result will be provided to theSupplier
to determine if another schedule should occur to re-run the task.If you want to ensure this does not reschedule forever consider using
scheduleWhile(SubmitterScheduler, long, boolean, Runnable, Supplier, long)
.- Parameters:
scheduler
- Scheduler to schedule out task executionsscheduleDelayMillis
- Delay after predicate indicating to loop again before re-executedfirstRunAsync
-False
to run first try on invoking thread,true
to submit on schedulertask
- Task to execute as long as test returnstrue
loopTest
- Test to see if scheduled loop should continue- Returns:
- Future that will resolve once returned
Supplier
returnsfalse
- Since:
- 5.0
-
scheduleWhile
public static ListenableFuture<?> scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.lang.Runnable task, java.util.function.Supplier<java.lang.Boolean> loopTest, long timeoutMillis)
Executes a task, checking the result from the task to see if it needs to reschedule the task again. This can be a good way to implement retry logic where a result ultimately needs to be communicated through a future.The returned future will only provide a result once the looping of the task has completed, or until the provided timeout is reached. If the timeout is reached then the task wont be rescheduled. Even if only 1 millisecond before timeout, the entire
rescheduleDelayMillis
will be provided for the next attempt's scheduled delay. On a timeout, iftrue
was provided fortimeoutProvideLastValue
then the future will be resolved with the last result provided. Iffalse
was provided then the future will complete in an error state, the cause of which being aTimeoutException
. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.The first execution will either be immediately executed in thread or submitted for immediate execution on the provided scheduler (depending on
firstRunAsync
parameter). Once this execution completes the result will be provided to theSupplier
to determine if another schedule should occur to re-run the task.- Parameters:
scheduler
- Scheduler to schedule out task executionsscheduleDelayMillis
- Delay after predicate indicating to loop again before re-executedfirstRunAsync
-False
to run first try on invoking thread,true
to submit on schedulertask
- Task to execute as long as test returnstrue
loopTest
- Test to see if scheduled loop should continuetimeoutMillis
- If greater than zero, wont reschedule and instead will just return the last result- Returns:
- Future that will resolve once returned
Supplier
returnsfalse
- Since:
- 5.0
-
scheduleWhile
public static <T> ListenableFuture<T> scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest)
Executes a task, checking the result from the task to see if it needs to reschedule the task again. This can be a good way to implement retry logic where a result ultimately needs to be communicated through a future.The returned future will only provide a result once the looping of the task has completed. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.
The first execution will either be immediately executed in thread or submitted for immediate execution on the provided scheduler (depending on
firstRunAsync
parameter). Once this execution completes the result will be provided to thePredicate
to determine if another schedule should occur to re-run the task.If you want to ensure this does not reschedule forever consider using
scheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate, long, boolean)
.- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
scheduler
- Scheduler to schedule out task executionsscheduleDelayMillis
- Delay after predicate indicating to loop again before re-executedfirstRunAsync
-False
to run first try on invoking thread,true
to submit on schedulertask
- Task which will provide result to compare in providedPredicate
loopTest
- Test for result to see if scheduled loop should continue- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
- Since:
- 5.0
-
scheduleWhile
public static <T> ListenableFuture<T> scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, boolean firstRunAsync, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean timeoutProvideLastValue)
Executes a task, checking the result from the task to see if it needs to reschedule the task again. This can be a good way to implement retry logic where a result ultimately needs to be communicated through a future.The returned future will only provide a result once the looping of the task has completed, or until the provided timeout is reached. If the timeout is reached then the task wont be rescheduled. Even if only 1 millisecond before timeout, the entire
rescheduleDelayMillis
will be provided for the next attempt's scheduled delay. On a timeout, iftrue
was provided fortimeoutProvideLastValue
then the future will be resolved with the last result provided. Iffalse
was provided then the future will complete in an error state, the cause of which being aTimeoutException
. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.The first execution will either be immediately executed in thread or submitted for immediate execution on the provided scheduler (depending on
firstRunAsync
parameter). Once this execution completes the result will be provided to thePredicate
to determine if another schedule should occur to re-run the task.- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
scheduler
- Scheduler to schedule out task executionsscheduleDelayMillis
- Delay after predicate indicating to loop again before re-executedfirstRunAsync
-False
to run first try on invoking thread,true
to submit on schedulertask
- Task which will provide result to compare in providedPredicate
loopTest
- Test for result to see if scheduled loop should continuetimeoutMillis
- If greater than zero, wont reschedule and instead will just return the last resulttimeoutProvideLastValue
- On timeoutfalse
will complete with a TimeoutException,true
completes with the last result- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
or timeout is reached - Since:
- 5.0
-
scheduleWhile
public static <T> ListenableFuture<T> scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest)
Executes a task, checking the result from the task to see if it needs to reschedule the task again. This can be a good way to implement retry logic where a result ultimately needs to be communicated through a future.The returned future will only provide a result once the looping of the task has completed. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.
The first execution will happen as soon as the provided
startingFuture
completes.If you want to ensure this does not reschedule forever consider using
scheduleWhile(SubmitterScheduler, long, ListenableFuture, Callable, Predicate, long, boolean)
.- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
scheduler
- Scheduler to schedule out task executionsscheduleDelayMillis
- Delay after predicate indicating to loop again before re-executedstartingFuture
- Future to use for first result to test for looptask
- Task which will provide result to compare in providedPredicate
loopTest
- Test for result to see if scheduled loop should continue- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
- Since:
- 5.0
-
scheduleWhile
public static <T> ListenableFuture<T> scheduleWhile(SubmitterScheduler scheduler, long scheduleDelayMillis, ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends T> task, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean timeoutProvideLastValue)
Executes a task, checking the result from the task to see if it needs to reschedule the task again. This can be a good way to implement retry logic where a result ultimately needs to be communicated through a future.The returned future will only provide a result once the looping of the task has completed, or until the provided timeout is reached. If the timeout is reached then the task wont be rescheduled. Even if only 1 millisecond before timeout, the entire
rescheduleDelayMillis
will be provided for the next attempt's scheduled delay. On a timeout, iftrue
was provided fortimeoutProvideLastValue
then the future will be resolved with the last result provided. Iffalse
was provided then the future will complete in an error state, the cause of which being aTimeoutException
. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.The first execution will happen as soon as the provided
startingFuture
completes.- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
scheduler
- Scheduler to schedule out task executionsscheduleDelayMillis
- Delay after predicate indicating to loop again before re-executedstartingFuture
- Future to use for first result to test for looptask
- Task which will provide result to compare in providedPredicate
loopTest
- Test for result to see if scheduled loop should continuetimeoutMillis
- If greater than zero, wont reschedule and instead will just return the last resulttimeoutProvideLastValue
- On timeoutfalse
will complete with a TimeoutException,true
completes with the last result- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
- Since:
- 5.0
-
executeWhile
public static <T> ListenableFuture<T> executeWhile(java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest)
Similar toscheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).In the end this is just another way to have a loop of async actions, checking results as they are provided but not resolving the returned future till the async action completes.
- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
asyncTask
- Callable to produce aListenableFuture
for when a result is readyloopTest
- The test to check the ready result to see if we need to keep looping- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
-
executeWhile
public static <T> ListenableFuture<T> executeWhile(java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean timeoutProvideLastValue)
Similar toscheduleWhile(SubmitterScheduler, long, boolean, Callable, Predicate, long, boolean)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).In the end this is just another way to have a loop of async actions, checking results as they are provided but not resolving the returned future till the async action completes. On a timeout, if
true
was provided fortimeoutProvideLastValue
then the future will be resolved with the last result provided. Iffalse
was provided then the future will complete in an error state, the cause of which being aTimeoutException
. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
asyncTask
- Callable to produce aListenableFuture
for when a result is readyloopTest
- The test to check the ready result to see if we need to keep loopingtimeoutMillis
- If greater than zero, wont reschedule and instead will just return the last resulttimeoutProvideLastValue
- On timeoutfalse
will complete with a TimeoutException,true
completes with the last result- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
-
executeWhile
public static <T> ListenableFuture<T> executeWhile(ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest)
Similar toscheduleWhile(SubmitterScheduler, long, ListenableFuture, Callable, Predicate)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).In the end this is just another way to have a loop of async actions, checking results as they are provided but not resolving the returned future till the async action completes.
- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
startingFuture
- Future to use for first result to test for loopasyncTask
- Callable to produce aListenableFuture
for when a result is readyloopTest
- The test to check the ready result to see if we need to keep looping- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
-
executeWhile
public static <T> ListenableFuture<T> executeWhile(ListenableFuture<? extends T> startingFuture, java.util.concurrent.Callable<? extends ListenableFuture<? extends T>> asyncTask, java.util.function.Predicate<? super T> loopTest, long timeoutMillis, boolean lastValueOnTimeout)
Similar toscheduleWhile(SubmitterScheduler, long, ListenableFuture, Callable, Predicate, long, boolean)
except that no executor is needed because the callable instead will return a future from the provided async submission (which may be a scheduled task or otherwise).In the end this is just another way to have a loop of async actions, checking results as they are provided but not resolving the returned future till the async action completes. On a timeout, if
true
was provided fortimeoutProvideLastValue
then the future will be resolved with the last result provided. Iffalse
was provided then the future will complete in an error state, the cause of which being aTimeoutException
. Canceling the returned future will prevent future executions from being attempted. Canceling with an interrupt will transmit the interrupt to the running task if it is currently running.- Type Parameters:
T
- The result object type returned by the task and provided by the future- Parameters:
startingFuture
- Future to use for first result to test for loopasyncTask
- Callable to produce aListenableFuture
for when a result is readyloopTest
- The test to check the ready result to see if we need to keep loopingtimeoutMillis
- If greater than zero, wont reschedule and instead will just return the last resultlastValueOnTimeout
- On timeoutfalse
will complete with a TimeoutException,true
completes with the last result- Returns:
- Future that will resolve once returned
Predicate
returnsfalse
-
-