@Override protected void attachFutureDoneTask(ListenableFuture<?> f, int index) { // we don't care about the result of the future // so to save a little memory we reuse the same task with no future provided // must be lazily set due to being invoked from super constructor if (doneTaskSingleton == null) { doneTaskSingleton = () -> { if (remainingResult.decrementAndGet() == 0) { setResult(getFinalResultList()); } }; } f.addListener(doneTaskSingleton, SameThreadSubmitterExecutor.instance()); } }
return (ListenableFuture<T>)makeCompleteFuture(futures); final EmptyFutureCollection efc = new EmptyFutureCollection(futures); if (efc.isDone()) { return immediateResultFuture(result); efc.addCallback(new FutureCallback<Object>() { @Override public void handleResult(Object ignored) {
return (ListenableFuture<T>)makeCompleteFuture(futures); final EmptyFutureCollection efc = new EmptyFutureCollection(futures); if (efc.isDone()) { return immediateResultFuture(result); efc.addCallback(new FutureCallback<Object>() { @Override public void handleResult(Object ignored) {
/** * An alternative to {@link #blockTillAllComplete(Iterable)}, this provides the ability to know * when all futures are complete without blocking. Unlike * {@link #blockTillAllComplete(Iterable)}, this requires that you provide a collection of * {@link ListenableFuture}'s. But will return immediately, providing a new * {@link ListenableFuture} that will be called once all the provided futures have finished. * <p> * The future returned will provide a {@code 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 using {@link #makeCompleteListFuture(Iterable)}. You should also consider using * {@link #makeFailurePropagatingCompleteFuture(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. * * @since 1.2.0 * @param futures Collection of futures that must finish before returned future is satisfied * @return ListenableFuture which will be done once all futures provided are done */ public static ListenableFuture<?> makeCompleteFuture(Iterable<? extends ListenableFuture<?>> futures) { ListenableFuture<?> result = new EmptyFutureCollection(futures); if (result.isDone()) { return ImmediateResultListenableFuture.NULL_RESULT; // might as well return a cheaper option } else { return result; } }
/** * An alternative to {@link #blockTillAllComplete(Iterable)}, this provides the ability to know * when all futures are complete without blocking. Unlike * {@link #blockTillAllComplete(Iterable)}, this requires that you provide a collection of * {@link ListenableFuture}'s. But will return immediately, providing a new * {@link ListenableFuture} that will be called once all the provided futures have finished. * <p> * The future returned will provide a {@code 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 using {@link #makeCompleteListFuture(Iterable)}. You should also consider using * {@link #makeFailurePropagatingCompleteFuture(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. * * @since 1.2.0 * @param futures Collection of futures that must finish before returned future is satisfied * @return ListenableFuture which will be done once all futures provided are done */ public static ListenableFuture<?> makeCompleteFuture(Iterable<? extends ListenableFuture<?>> futures) { ListenableFuture<?> result = new EmptyFutureCollection(futures); if (result.isDone()) { return ImmediateResultListenableFuture.NULL_RESULT; // might as well return a cheaper option } else { return result; } }
@Override protected void attachFutureDoneTask(ListenableFuture<?> f, int index) { // we don't care about the result of the future // so to save a little memory we reuse the same task with no future provided // must be lazily set due to being invoked from super constructor if (doneTaskSingleton == null) { doneTaskSingleton = () -> { if (remainingResult.decrementAndGet() == 0) { setResult(getFinalResultList()); } }; } f.addListener(doneTaskSingleton, SameThreadSubmitterExecutor.instance()); } }