### Question:
Future implements java.util.concurrent.Future<T> { public static Future<Void> waitAll(final Future<?>... futures) { if (futures == null) { throw new NullPointerException("futures must not be null!"); } if (futures.length == 0) return Future.of(null); class WaitData { int runningFutures = futures.length; boolean stopped; } final WaitData waitData = new WaitData(); final Promise<Void> promise = new Promise<Void>(); promise.setOnCancel(new Promise.CancelRequestCallback<Void>() { @Override public void onCancelRequested(Promise<Void> promise) { for (Future<?> future : futures) { future.requestCancellation(); } } }); for (Future<?> future : futures) { ((Future<Object>) future).connect(new Future.Callback<Object>() { @Override public void onFinished(Future<Object> future) { synchronized (waitData) { if (!waitData.stopped) { if (future.isCancelled()) { promise.setCancelled(); waitData.stopped = true; } else if (future.hasError()) { promise.setError(future.getErrorMessage()); waitData.stopped = true; } else { waitData.runningFutures--; if (waitData.runningFutures == 0) { promise.setValue(null); } } } } } }); } return promise.getFuture(); } Future(final long pFuture); static Future<T> of(final T value); static Future<T> cancelled(); static Future<T> fromError(String errorMessage); void sync(long timeout, TimeUnit unit); void sync(); void connect(Callback<T> callback, FutureCallbackType futureCallbackType); void connect(final Callback<T> callback); @Override boolean cancel(boolean mayInterruptIfRunning); synchronized void requestCancellation(); @Deprecated synchronized boolean cancel(); @Override T get(); @Override T get(long timeout, TimeUnit unit); T getValue(); ExecutionException getError(); boolean hasError(); String getErrorMessage(); @Override synchronized boolean isCancelled(); @Override synchronized boolean isDone(); synchronized boolean isSuccess(); Future<R> thenApply(final Function<Future<T>, R> function); Future<Void> thenConsume(final Consumer<Future<T>> consumer); Future<R> thenCompose(final Function<Future<T>, Future<R>> function); Future<R> andThenApply(final Function<T, R> function); Future<Void> andThenConsume(final Consumer<T> consumer); Future<R> andThenCompose(final Function<T, Future<R>> function); static Future<Void> waitAll(final Future<?>... futures); Future<T> waitFor(final Future<?>... futures);  }### Answer:
@Test public void testWaitAll() throws ExecutionException, TimeoutException { Promise<Long> p1 = new Promise<Long>(); Promise<Long> p2 = new Promise<Long>(); Promise<Long> p3 = new Promise<Long>(); new Thread(new AsyncWait(p1, 100, AsyncWait.Type.VALUE)).start(); new Thread(new AsyncWait(p2, 200, AsyncWait.Type.VALUE)).start(); p3.setValue(42L); Future<Long> f1 = p1.getFuture(); Future<Long> f2 = p2.getFuture(); Future<Long> f3 = p3.getFuture(); Future.waitAll(f1, f2, f3).get(); assertEquals(100, (long) f1.get(0, TimeUnit.SECONDS)); assertEquals(200, (long) f2.get(0, TimeUnit.SECONDS)); assertEquals(42, (long) f3.get(0, TimeUnit.SECONDS)); }