Skip to content

Commit

Permalink
Deprecate CompositeFuture static methods and provide alternatives on …
Browse files Browse the repository at this point in the history
…the Future type that declares generic types using wildcard instead of using raw types. The raw types were necessary because of a limitation with the code generator when Future / CompositeFuture were generated types. Since this limitation is gone we can provide better declarations.
  • Loading branch information
vietj committed May 16, 2023
1 parent 8375fd3 commit f8c6965
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 17 deletions.
11 changes: 4 additions & 7 deletions src/main/asciidoc/futures.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Beyond this, {@link io.vertx.core.Future} offers more: `map`, `recover`, `otherw
Coordination of multiple futures can be achieved with Vert.x {@link io.vertx.core.Future futures}.
It supports concurrent composition (run several async operations in parallel) and sequential composition (chain async operations).
{@link io.vertx.core.CompositeFuture#all} takes several futures arguments (up to 6) and returns a future that is
{@link io.vertx.core.Future#all} takes several futures arguments (up to 6) and returns a future that is
_succeeded_ when all the futures are _succeeded_ and _failed_ when at least one of the futures is failed:

[source,$lang]
Expand All @@ -93,8 +93,7 @@ The operations run concurrently, the {@link io.vertx.core.Handler} attached to t
When one of the operation fails (one of the passed future is marked as a failure), the resulting future is marked as failed too.
When all the operations succeed, the resulting future is completed with a success.

On success, the `resultAt` method guarantees the results in the same order specified in the call to `CompositeFuture.all`. In the example above, regardless of which
item completed first, the `httpServer` result can be accessed using `resultAt(0)` and the `netServer` result can be accessed using `resultAt(1)`.
On success, the `resultAt` method guarantees the results in the same order specified in the call to `Future.all`. In the example above, regardless of which item completed first, the `httpServer` result can be accessed using `resultAt(0)` and the `netServer` result can be accessed using `resultAt(1)`.

Alternatively, you can pass a list (potentially empty) of futures:

Expand All @@ -103,8 +102,7 @@ Alternatively, you can pass a list (potentially empty) of futures:
{@link examples.CoreExamples#exampleFutureAll2}
----

While the `all` composition _waits_ until all futures are successful (or one fails), the `any` composition
_waits_ for the first succeeded future. {@link io.vertx.core.CompositeFuture#any} takes several futures arguments (up to 6) and returns a future that is succeeded when one of the futures is, and failed when all the futures are failed:
While the `all` composition _waits_ until all futures are successful (or one fails), the `any` composition _waits_ for the first succeeded future. {@link io.vertx.core.Future#any} takes several futures arguments (up to 6) and returns a future that is succeeded when one of the futures is, and failed when all the futures are failed:

[source,$lang]
----
Expand All @@ -118,8 +116,7 @@ A list of futures can be used also:
{@link examples.CoreExamples#exampleFutureAny2}
----

The `join` composition _waits_ until all futures are completed, either with a success or a failure.
{@link io.vertx.core.CompositeFuture#join} takes several futures arguments (up to 6) and returns a future that is succeeded when all the futures are succeeded, and failed when all the futures are completed and at least one of them is failed:
The `join` composition _waits_ until all futures are completed, either with a success or a failure. {@link io.vertx.core.Future#join} takes several futures arguments (up to 6) and returns a future that is succeeded when all the futures are succeeded, and failed when all the futures are completed and at least one of them is failed:

[source,$lang]
----
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/examples/CoreExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void exampleFutureAll1(HttpServer httpServer, NetServer netServer) {

Future<NetServer> netServerFuture = netServer.listen();

CompositeFuture.all(httpServerFuture, netServerFuture).onComplete(ar -> {
Future.all(httpServerFuture, netServerFuture).onComplete(ar -> {
if (ar.succeeded()) {
// All servers started
} else {
Expand All @@ -189,12 +189,12 @@ public void exampleFutureAll1(HttpServer httpServer, NetServer netServer) {
});
}

public void exampleFutureAll2(Future future1, Future future2, Future future3) {
CompositeFuture.all(Arrays.asList(future1, future2, future3));
public void exampleFutureAll2(Future<?> future1, Future<?> future2, Future<?> future3) {
Future.all(Arrays.asList(future1, future2, future3));
}

public void exampleFutureAny1(Future<String> future1, Future<String> future2) {
CompositeFuture.any(future1, future2).onComplete(ar -> {
Future.any(future1, future2).onComplete(ar -> {
if (ar.succeeded()) {
// At least one is succeeded
} else {
Expand All @@ -203,12 +203,12 @@ public void exampleFutureAny1(Future<String> future1, Future<String> future2) {
});
}

public void exampleFutureAny2(Future f1, Future f2, Future f3) {
CompositeFuture.any(Arrays.asList(f1, f2, f3));
public void exampleFutureAny2(Future<?> f1, Future<?> f2, Future<?> f3) {
Future.any(Arrays.asList(f1, f2, f3));
}

public void exampleFutureJoin1(Future future1, Future future2, Future future3) {
CompositeFuture.join(future1, future2, future3).onComplete(ar -> {
public void exampleFutureJoin1(Future<?> future1, Future<?> future2, Future<?> future3) {
Future.join(future1, future2, future3).onComplete(ar -> {
if (ar.succeeded()) {
// All succeeded
} else {
Expand All @@ -217,8 +217,8 @@ public void exampleFutureJoin1(Future future1, Future future2, Future future3) {
});
}

public void exampleFutureJoin2(Future future1, Future future2, Future future3) {
CompositeFuture.join(Arrays.asList(future1, future2, future3));
public void exampleFutureJoin2(Future<?> future1, Future<?> future2, Future<?> future3) {
Future.join(Arrays.asList(future1, future2, future3));
}

public void example7_1(Vertx vertx) {
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/io/vertx/core/CompositeFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,45 @@ public interface CompositeFuture extends Future<CompositeFuture> {
* @param f1 future
* @param f2 future
* @return the composite future
* @deprecated instead use {@link Future#all(Future, Future)}
*/
@Deprecated
static <T1, T2> CompositeFuture all(Future<T1> f1, Future<T2> f2) {
return CompositeFutureImpl.all(f1, f2);
}

/**
* Like {@link #all(Future, Future)} but with 3 futures.
* @deprecated instead use {@link Future#all(Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3> CompositeFuture all(Future<T1> f1, Future<T2> f2, Future<T3> f3) {
return CompositeFutureImpl.all(f1, f2, f3);
}

/**
* Like {@link #all(Future, Future)} but with 4 futures.
* @deprecated instead use {@link Future#all(Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4> CompositeFuture all(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4) {
return CompositeFutureImpl.all(f1, f2, f3, f4);
}

/**
* Like {@link #all(Future, Future)} but with 5 futures.
* @deprecated instead use {@link Future#all(Future, Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4, T5> CompositeFuture all(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5) {
return CompositeFutureImpl.all(f1, f2, f3, f4, f5);
}

/**
* Like {@link #all(Future, Future)} but with 6 futures.
* @deprecated instead use {@link Future#all(Future, Future, Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4, T5, T6> CompositeFuture all(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5, Future<T6> f6) {
return CompositeFutureImpl.all(f1, f2, f3, f4, f5, f6);
}
Expand All @@ -71,7 +81,9 @@ static <T1, T2, T3, T4, T5, T6> CompositeFuture all(Future<T1> f1, Future<T2> f2
* Like {@link #all(Future, Future)} but with a list of futures.<p>
*
* When the list is empty, the returned future will be already completed.
* @deprecated instead use {@link Future#all(List)}
*/
@Deprecated
static CompositeFuture all(List<Future> futures) {
return CompositeFutureImpl.all(futures.toArray(new Future[0]));
}
Expand All @@ -84,35 +96,45 @@ static CompositeFuture all(List<Future> futures) {
* @param f1 future
* @param f2 future
* @return the composite future
* @deprecated instead use {@link Future#any(Future, Future)}
*/
@Deprecated
static <T1, T2> CompositeFuture any(Future<T1> f1, Future<T2> f2) {
return CompositeFutureImpl.any(f1, f2);
}

/**
* Like {@link #any(Future, Future)} but with 3 futures.
* @deprecated instead use {@link Future#any(Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3> CompositeFuture any(Future<T1> f1, Future<T2> f2, Future<T3> f3) {
return CompositeFutureImpl.any(f1, f2, f3);
}

/**
* Like {@link #any(Future, Future)} but with 4 futures.
* @deprecated instead use {@link Future#any(Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4> CompositeFuture any(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4) {
return CompositeFutureImpl.any(f1, f2, f3, f4);
}

/**
* Like {@link #any(Future, Future)} but with 5 futures.
* @deprecated instead use {@link Future#any(Future, Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4, T5> CompositeFuture any(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5) {
return CompositeFutureImpl.any(f1, f2, f3, f4, f5);
}

/**
* Like {@link #any(Future, Future)} but with 6 futures.
* @deprecated instead use {@link Future#any(Future, Future, Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4, T5, T6> CompositeFuture any(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5, Future<T6> f6) {
return CompositeFutureImpl.any(f1, f2, f3, f4, f5, f6);
}
Expand All @@ -121,7 +143,9 @@ static <T1, T2, T3, T4, T5, T6> CompositeFuture any(Future<T1> f1, Future<T2> f2
* Like {@link #any(Future, Future)} but with a list of futures.<p>
*
* When the list is empty, the returned future will be already completed.
* @deprecated instead use {@link Future#any(List)}
*/
@Deprecated
static CompositeFuture any(List<Future> futures) {
return CompositeFutureImpl.any(futures.toArray(new Future[0]));
}
Expand All @@ -134,35 +158,45 @@ static CompositeFuture any(List<Future> futures) {
* @param f1 future
* @param f2 future
* @return the composite future
* @deprecated instead use {@link Future#join(Future, Future)}
*/
@Deprecated
static <T1, T2> CompositeFuture join(Future<T1> f1, Future<T2> f2) {
return CompositeFutureImpl.join(f1, f2);
}

/**
* Like {@link #join(Future, Future)} but with 3 futures.
* @deprecated instead use {@link Future#join(Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3> CompositeFuture join(Future<T1> f1, Future<T2> f2, Future<T3> f3) {
return CompositeFutureImpl.join(f1, f2, f3);
}

/**
* Like {@link #join(Future, Future)} but with 4 futures.
* @deprecated instead use {@link Future#join(Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4> CompositeFuture join(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4) {
return CompositeFutureImpl.join(f1, f2, f3, f4);
}

/**
* Like {@link #join(Future, Future)} but with 5 futures.
* @deprecated instead use {@link Future#join(Future, Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4, T5> CompositeFuture join(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5) {
return CompositeFutureImpl.join(f1, f2, f3, f4, f5);
}

/**
* Like {@link #join(Future, Future)} but with 6 futures.
* @deprecated instead use {@link Future#join(Future, Future, Future, Future, Future, Future)}
*/
@Deprecated
static <T1, T2, T3, T4, T5, T6> CompositeFuture join(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5, Future<T6> f6) {
return CompositeFutureImpl.join(f1, f2, f3, f4, f5, f6);
}
Expand All @@ -171,7 +205,9 @@ static <T1, T2, T3, T4, T5, T6> CompositeFuture join(Future<T1> f1, Future<T2> f
* Like {@link #join(Future, Future)} but with a list of futures.<p>
*
* When the list is empty, the returned future will be already completed.
* @deprecated instead use {@link Future#join(List)}
*/
@Deprecated
static CompositeFuture join(List<Future> futures) {
return CompositeFutureImpl.join(futures.toArray(new Future[0]));
}
Expand Down
Loading

0 comments on commit f8c6965

Please sign in to comment.