io.vertx.core.CompositeFuture Maven / Gradle / Ivy
/*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.vertx.core;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.impl.CompositeFutureImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
* The composite future wraps a list of {@link Future futures}, it is useful when several futures
* needs to be coordinated.
*
* @author Julien Viet
*/
@VertxGen
public interface CompositeFuture extends Future {
/**
* Return a composite future, succeeded when all futures are succeeded, failed when any future is failed.
*
* The returned future fails as soon as one of {@code f1} or {@code f2} fails.
*
* @param f1 future
* @param f2 future
* @return the composite future
*/
static CompositeFuture all(Future f1, Future f2) {
return CompositeFutureImpl.all(f1, f2);
}
/**
* Like {@link #all(Future, Future)} but with 3 futures.
*/
static CompositeFuture all(Future f1, Future f2, Future f3) {
return CompositeFutureImpl.all(f1, f2, f3);
}
/**
* Like {@link #all(Future, Future)} but with 4 futures.
*/
static CompositeFuture all(Future f1, Future f2, Future f3, Future f4) {
return CompositeFutureImpl.all(f1, f2, f3, f4);
}
/**
* Like {@link #all(Future, Future)} but with 5 futures.
*/
static CompositeFuture all(Future f1, Future f2, Future f3, Future f4, Future f5) {
return CompositeFutureImpl.all(f1, f2, f3, f4, f5);
}
/**
* Like {@link #all(Future, Future)} but with 6 futures.
*/
static CompositeFuture all(Future f1, Future f2, Future f3, Future f4, Future f5, Future f6) {
return CompositeFutureImpl.all(f1, f2, f3, f4, f5, f6);
}
/**
* Like {@link #all(Future, Future)} but with a list of futures.
*
* When the list is empty, the returned future will be already completed.
*/
static CompositeFuture all(List futures) {
return CompositeFutureImpl.all(futures.toArray(new Future[futures.size()]));
}
/**
* Return a composite future, succeeded when any futures is succeeded, failed when all futures are failed.
*
* The returned future succeeds as soon as one of {@code f1} or {@code f2} succeeds.
*
* @param f1 future
* @param f2 future
* @return the composite future
*/
static CompositeFuture any(Future f1, Future f2) {
return CompositeFutureImpl.any(f1, f2);
}
/**
* Like {@link #any(Future, Future)} but with 3 futures.
*/
static CompositeFuture any(Future f1, Future f2, Future f3) {
return CompositeFutureImpl.any(f1, f2, f3);
}
/**
* Like {@link #any(Future, Future)} but with 4 futures.
*/
static CompositeFuture any(Future f1, Future f2, Future f3, Future f4) {
return CompositeFutureImpl.any(f1, f2, f3, f4);
}
/**
* Like {@link #any(Future, Future)} but with 5 futures.
*/
static CompositeFuture any(Future f1, Future f2, Future f3, Future f4, Future f5) {
return CompositeFutureImpl.any(f1, f2, f3, f4, f5);
}
/**
* Like {@link #any(Future, Future)} but with 6 futures.
*/
static CompositeFuture any(Future f1, Future f2, Future f3, Future f4, Future f5, Future f6) {
return CompositeFutureImpl.any(f1, f2, f3, f4, f5, f6);
}
/**
* Like {@link #any(Future, Future)} but with a list of futures.
*
* When the list is empty, the returned future will be already completed.
*/
static CompositeFuture any(List futures) {
return CompositeFutureImpl.any(futures.toArray(new Future[futures.size()]));
}
@Override
CompositeFuture setHandler(Handler> handler);
/**
* Returns a cause of a wrapped future
*
* @param index the wrapped future index
*/
Throwable cause(int index);
/**
* Returns true if a wrapped future is succeeded
*
* @param index the wrapped future index
*/
boolean succeeded(int index);
/**
* Returns true if a wrapped future is failed
*
* @param index the wrapped future index
*/
boolean failed(int index);
/**
* Returns true if a wrapped future is completed
*
* @param index the wrapped future index
*/
boolean isComplete(int index);
/**
* Returns the result of a wrapped future
*
* @param index the wrapped future index
*/
T result(int index);
/**
* @return the number of wrapped future
*/
int size();
/**
* @return a list of the current completed values. If one future is not yet resolved or is failed, {@code} null
* will be used
*/
@GenIgnore
default List list() {
int size = size();
ArrayList list = new ArrayList<>(size);
for (int index = 0;index < size;index++) {
list.add(result(index));
}
return list;
}
}