List of usage examples for io.vertx.core CompositeFuture join
static CompositeFuture join(List<Future> futures)
When the list is empty, the returned future will be already completed.
From source file:examples.CoreExamples.java
License:Open Source License
public void exampleFutureJoin2(Future future1, Future future2, Future future3) { CompositeFuture.join(Arrays.asList(future1, future2, future3)); }
From source file:io.engagingspaces.vertx.dataloader.DataLoader.java
License:Open Source License
/** * Requests to load the list of data provided by the specified keys asynchronously, and returns a composite future * of the resulting values./*www .ja va 2 s . c om*/ * <p> * If batching is enabled (the default), you'll have to call {@link DataLoader#dispatch()} at a later stage to * start batch execution. If you forget this call the future will never be completed (unless already completed, * and returned from cache). * * @param keys the list of keys to load * @return the composite future of the list of values */ public CompositeFuture loadMany(List<K> keys) { return CompositeFuture.join(keys.stream().map(this::load).collect(Collectors.toList())); }
From source file:io.engagingspaces.vertx.dataloader.DataLoader.java
License:Open Source License
/** * Dispatches the queued load requests to the batch execution function and returns a composite future of the result. * <p>/*from www . j a v a 2 s .c o m*/ * If batching is disabled, or there are no queued requests, then a succeeded composite future is returned. * * @return the composite future of the queued load requests */ public CompositeFuture dispatch() { if (!loaderOptions.batchingEnabled() || loaderQueue.size() == 0) { return CompositeFuture.join(Collections.emptyList()); } CompositeFuture batch = batchLoadFunction.load(loaderQueue.keySet()); dispatchedQueues.put(batch, new LinkedHashMap<>(loaderQueue)); batch.setHandler(rh -> { AtomicInteger index = new AtomicInteger(0); dispatchedQueues.get(batch).forEach((key, future) -> { if (batch.succeeded(index.get())) { future.complete(batch.resultAt(index.get())); } else { future.fail(batch.cause(index.get())); } index.incrementAndGet(); }); dispatchedQueues.remove(batch); }); loaderQueue.clear(); return batch; }