private void updateSignalAndStatusFutures() { dataSignalFuture = whenAnyComplete(dataRequests); statusFuture = toCompletableFuture(nonCancellationPropagating(dataSignalFuture)); }
@Test public void testWhenAnyCompleteCancelOthers() throws Exception { assertGetUncheckedListenable(future -> { SettableFuture<Object> future1 = SettableFuture.create(); SettableFuture<Object> future3 = SettableFuture.create(); Object result = getFutureValue(whenAnyCompleteCancelOthers(ImmutableList.of(future1, future, future3))); assertTrue(future1.isCancelled()); assertTrue(future3.isCancelled()); return result; }); assertFailure(() -> whenAnyComplete(null), e -> assertInstanceOf(e, NullPointerException.class)); assertFailure(() -> whenAnyComplete(ImmutableList.of()), e -> assertInstanceOf(e, IllegalArgumentException.class)); assertEquals( tryGetFutureValue(whenAnyComplete(ImmutableList.of(SettableFuture.create(), SettableFuture.create())), 10, MILLISECONDS), Optional.empty()); }
return new ScheduleResult(sourceSchedulers.isEmpty(), newTasks, whenAnyComplete(blocked), blockedReason, splitsScheduled);
@Test public void testWhenAnyCompleteCancelOthers() throws Exception { assertGetUncheckedListenable(future -> { SettableFuture<Object> future1 = SettableFuture.create(); SettableFuture<Object> future3 = SettableFuture.create(); Object result = getFutureValue(whenAnyCompleteCancelOthers(ImmutableList.of(future1, future, future3))); assertTrue(future1.isCancelled()); assertTrue(future3.isCancelled()); return result; }); assertFailure(() -> whenAnyComplete(null), e -> assertInstanceOf(e, NullPointerException.class)); assertFailure(() -> whenAnyComplete(ImmutableList.of()), e -> assertInstanceOf(e, IllegalArgumentException.class)); assertEquals( tryGetFutureValue(whenAnyComplete(ImmutableList.of(SettableFuture.create(), SettableFuture.create())), 10, MILLISECONDS), Optional.empty()); }
false, overallNewTasks.build(), nonCancellationPropagating(whenAnyComplete(overallBlockedFutures)), blockedReason, overallSplitAssignmentCount);
tryGetFutureValue(whenAnyComplete(blockedStages), 1, SECONDS);
private void updateSignalAndStatusFutures() { dataSignalFuture = whenAnyComplete(dataRequests); statusFuture = toCompletableFuture(nonCancellationPropagating(dataSignalFuture)); }
/** * Creates a future that completes when the first future completes either normally * or exceptionally. All other futures are cancelled when one completes. * Cancellation of the returned future propagates to the supplied futures. * <p> * It is critical for the performance of this function that * {@code guava.concurrent.generate_cancellation_cause} is false, * which is the default since Guava v20. */ public static <V> ListenableFuture<V> whenAnyCompleteCancelOthers(Iterable<? extends ListenableFuture<? extends V>> futures) { requireNonNull(futures, "futures is null"); checkArgument(!isEmpty(futures), "futures is empty"); // wait for the first task to unblock and then cancel all futures to free up resources ListenableFuture<V> anyComplete = whenAnyComplete(futures); anyComplete.addListener( () -> { for (ListenableFuture<?> future : futures) { future.cancel(true); } }, directExecutor()); return anyComplete; }
/** * Creates a future that completes when the first future completes either normally * or exceptionally. All other futures are cancelled when one completes. * Cancellation of the returned future propagates to the supplied futures. * <p> * It is critical for the performance of this function that * {@code guava.concurrent.generate_cancellation_cause} is false, * which is the default since Guava v20. */ public static <V> ListenableFuture<V> whenAnyCompleteCancelOthers(Iterable<? extends ListenableFuture<? extends V>> futures) { requireNonNull(futures, "futures is null"); checkArgument(!isEmpty(futures), "futures is empty"); // wait for the first task to unblock and then cancel all futures to free up resources ListenableFuture<V> anyComplete = whenAnyComplete(futures); anyComplete.addListener( () -> { for (ListenableFuture<?> future : futures) { future.cancel(true); } }, directExecutor()); return anyComplete; }
@Test public void testWhenAnyComplete() throws Exception { assertGetUncheckedListenable(future -> getFutureValue(whenAnyComplete(ImmutableList.of(SettableFuture.create(), future, SettableFuture.create())))); assertFailure(() -> whenAnyComplete(null), e -> assertInstanceOf(e, NullPointerException.class)); assertFailure(() -> whenAnyComplete(ImmutableList.of()), e -> assertInstanceOf(e, IllegalArgumentException.class)); assertEquals( tryGetFutureValue(whenAnyComplete(ImmutableList.of(SettableFuture.create(), SettableFuture.create())), 10, MILLISECONDS), Optional.empty()); }
@Test public void testWhenAnyComplete() throws Exception { assertGetUncheckedListenable(future -> getFutureValue(whenAnyComplete(ImmutableList.of(SettableFuture.create(), future, SettableFuture.create())))); assertFailure(() -> whenAnyComplete(null), e -> assertInstanceOf(e, NullPointerException.class)); assertFailure(() -> whenAnyComplete(ImmutableList.of()), e -> assertInstanceOf(e, IllegalArgumentException.class)); assertEquals( tryGetFutureValue(whenAnyComplete(ImmutableList.of(SettableFuture.create(), SettableFuture.create())), 10, MILLISECONDS), Optional.empty()); }
return new ScheduleResult(sourceSchedulers.isEmpty(), newTasks, whenAnyComplete(blocked), blockedReason, splitsScheduled);
return new ScheduleResult(sourceSchedulers.isEmpty(), newTasks, whenAnyComplete(blocked), blockedReason, splitsScheduled);
false, overallNewTasks.build(), nonCancellationPropagating(whenAnyComplete(overallBlockedFutures)), blockedReason, overallSplitAssignmentCount);
false, overallNewTasks.build(), nonCancellationPropagating(whenAnyComplete(overallBlockedFutures)), blockedReason, overallSplitAssignmentCount);
tryGetFutureValue(whenAnyComplete(blockedStages), 1, SECONDS);
tryGetFutureValue(whenAnyComplete(blockedStages), 1, SECONDS);