CompletableFuture<List<T>> result = CompletableFuture.allOf(com.toArray(new CompletableFuture[com.size()])) .thenApply(v -> com.stream() .map(CompletableFuture::join) .collect(toList()) ); com.forEach(f -> f.whenComplete((t, ex) -> { if (ex != null) { result.completeExceptionally(ex); } })); return result;
/** * Return a future that represents the completion of the futures in the provided list * * @param futures * @return */ public static <T> CompletableFuture<Void> waitForAll(List<CompletableFuture<T>> futures) { return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); }
public static <R> CompletableFuture<List<R>> sequenceFuture(List<CompletableFuture<R>> futures) { return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) .thenApply(v -> futures.stream() .map(AsyncUtils::getValue) .filter(Objects::nonNull) .collect(Collectors.toList()) ); }
@Override public CompletableFuture<Void> flushAsync() { List<CompletableFuture<Void>> flushFutures = producers.stream().map(ProducerImpl::flushAsync).collect(Collectors.toList()); return CompletableFuture.allOf(flushFutures.toArray(new CompletableFuture[flushFutures.size()])); }
private CompletableFuture<Void> rollback(Set<TransactionParticipant<?>> participants) { return CompletableFuture.allOf(participants.stream() .map(TransactionParticipant::rollback) .toArray(CompletableFuture[]::new)); }
private CompletableFuture<Void> commit(Set<TransactionParticipant<?>> participants) { return CompletableFuture.allOf(participants.stream() .map(TransactionParticipant::commit) .toArray(CompletableFuture[]::new)); }
/** * Blocks until all of the synchronous listeners have finished processing the events this thread * published. */ public void awaitSynchronous() { List<CompletableFuture<Void>> futures = pending.get(); if (futures.isEmpty()) { return; } try { CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[0])).join(); } catch (CompletionException e) { logger.log(Level.WARNING, null, e); } finally { futures.clear(); } }
static<T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> com) { return CompletableFuture.allOf(com.toArray(new CompletableFuture[com.size()])) .thenApply(v -> com.stream() .map(CompletableFuture::join) .collect(toList()) ); }
private CompletableFuture<List<T>> createPublicStage(Map<RedisClusterNode, CompletableFuture<T>> map) { return CompletableFuture.allOf(map.values().toArray(new CompletableFuture[0])).thenApply(ignore -> { List<T> results = new ArrayList<>(map.size()); for (CompletionStage<? extends T> value : map.values()) { results.add(value.toCompletableFuture().join()); } return results; }); }
/** * Create a composite {@link CompletableFuture} is composed from the given {@code futures}. * * @param futures must not be {@literal null}. * @return the composed {@link CompletableFuture}. * @since 5.1.1 */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static CompletableFuture<Void> allOf(Collection<? extends CompletableFuture<?>> futures) { LettuceAssert.notNull(futures, "Futures must not be null"); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); }
static <T> CompletableFuture<List<T>> allOf(List<CompletableFuture<T>> futures) { return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) .thenApply(v -> futures.stream().map(f -> f.getNow(null)).collect(toList())); }
@Override public CompletableFuture<ManagedPartitionGroup> connect(PartitionManagementService managementService) { int threadPoolSize = Math.max(Math.min(Runtime.getRuntime().availableProcessors() * 2, 32), 4); threadFactory = new BlockingAwareThreadPoolContextFactory("atomix-" + name() + "-%d", threadPoolSize, LOGGER); List<CompletableFuture<Partition>> futures = partitions.values().stream() .map(p -> p.connect(managementService, threadFactory)) .collect(Collectors.toList()); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> { LOGGER.info("Started"); return this; }); }
@Override public CompletableFuture<ManagedPartitionGroup> connect(PartitionManagementService managementService) { int threadPoolSize = Math.max(Math.min(Runtime.getRuntime().availableProcessors() * 2, 32), 4); threadFactory = new BlockingAwareThreadPoolContextFactory("atomix-" + name() + "-%d", threadPoolSize, LOGGER); List<CompletableFuture<Partition>> futures = partitions.values().stream() .map(p -> p.connect(managementService, threadFactory)) .collect(Collectors.toList()); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenApply(v -> { LOGGER.info("Started"); return this; }); }
@Override public CompletableFuture<ManagedPartitionGroup> join(PartitionManagementService managementService) { int threadPoolSize = Math.max(Math.min(Runtime.getRuntime().availableProcessors() * 2, 32), 4); threadFactory = new BlockingAwareThreadPoolContextFactory("atomix-" + name() + "-%d", threadPoolSize, LOGGER); List<CompletableFuture<Partition>> futures = partitions.values().stream() .map(p -> p.join(managementService, threadFactory)) .collect(Collectors.toList()); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> { LOGGER.info("Started"); return this; }); }
/** * Updates all active peers with a given subscription. */ private CompletableFuture<Void> updateNodes() { List<CompletableFuture<Void>> futures = membershipService.getMembers() .stream() .filter(node -> !localMemberId.equals(node.id())) .map(this::updateNode) .collect(Collectors.toList()); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])); }
public PipelinedRedisFuture(Map<?, ? extends CompletionStage<?>> executions, Function<PipelinedRedisFuture<V>, V> converter) { CompletableFuture.allOf(executions.values().toArray(new CompletableFuture<?>[0])) .thenRun(() -> complete(converter.apply(this))).exceptionally(throwable -> { completeExceptionally(throwable); return null; }); }
@Override public CompletableFuture<Void> closeAsync() { return CompletableFuture.allOf(super.closeAsync(), sentinelTopologyRefresh.closeAsync()); } };
@Override public CompletableFuture<Void> shutdown() { final CompletableFuture<Void> f1; final CompletableFuture<Void> f2; try { f1 = AccessLogWriter.this.shutdown(); } finally { f2 = after.shutdown(); } return CompletableFuture.allOf(f1, f2); } };
public static <T> CompletableFuture<List<T>> allOf(final Collection<CompletableFuture<T>> futures) { CompletableFuture[] cfs = futures.toArray(new CompletableFuture[futures.size()]); return CompletableFuture.allOf(cfs) .thenApply(vd -> futures.stream() .map(CompletableFuture::join) .collect(Collectors.toList()) ); } }
private CompletableFuture<Void> stopSupportingActorsAsync() { FiniteDuration stopTimeout = new FiniteDuration(5L, TimeUnit.SECONDS); CompletableFuture<Boolean> stopTaskMonitorFuture = stopActor(taskMonitor, stopTimeout); taskMonitor = null; CompletableFuture<Boolean> stopConnectionMonitorFuture = stopActor(connectionMonitor, stopTimeout); connectionMonitor = null; CompletableFuture<Boolean> stopLaunchCoordinatorFuture = stopActor(launchCoordinator, stopTimeout); launchCoordinator = null; CompletableFuture<Boolean> stopReconciliationCoordinatorFuture = stopActor(reconciliationCoordinator, stopTimeout); reconciliationCoordinator = null; return CompletableFuture.allOf( stopTaskMonitorFuture, stopConnectionMonitorFuture, stopLaunchCoordinatorFuture, stopReconciliationCoordinatorFuture); }