Skip to content

Commit

Permalink
Missing javadoc + minor rename to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jan 15, 2016
1 parent ff0ff20 commit 9b6bbec
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/main/asciidoc/java/index.adoc
Expand Up @@ -299,10 +299,10 @@ _succeeded_ when all the futures are and _failed_ otherwise:
[source,java] [source,java]
---- ----
Future<HttpServer> httpServerFuture = Future.future(); Future<HttpServer> httpServerFuture = Future.future();
httpServer.listen(httpServerFuture.handler()); httpServer.listen(httpServerFuture.completer());
Future<NetServer> netServerFuture = Future.future(); Future<NetServer> netServerFuture = Future.future();
netServer.listen(netServerFuture.handler()); netServer.listen(netServerFuture.completer());
CompositeFuture.all(httpServerFuture, netServerFuture).setHandler(ar -> { CompositeFuture.all(httpServerFuture, netServerFuture).setHandler(ar -> {
if (ar.succeeded()) { if (ar.succeeded()) {
Expand All @@ -313,7 +313,7 @@ CompositeFuture.all(httpServerFuture, netServerFuture).setHandler(ar -> {
}); });
---- ----


The handler returned by `link:../../apidocs/io/vertx/core/Future.html#handler--[handler]` completes the future. The handler returned by `link:../../apidocs/io/vertx/core/Future.html#completer--[completer]` completes the future.


`link:../../apidocs/io/vertx/core/CompositeFuture.html#any-io.vertx.core.Future-io.vertx.core.Future-[CompositeFuture.any]` takes several futures arguments (up to 6) and returns a future that is `link:../../apidocs/io/vertx/core/CompositeFuture.html#any-io.vertx.core.Future-io.vertx.core.Future-[CompositeFuture.any]` takes several futures arguments (up to 6) and returns a future that is
_failed_ when all the futures are and _succeeded_ otherwise: _failed_ when all the futures are and _succeeded_ otherwise:
Expand All @@ -340,12 +340,12 @@ FileSystem fs = vertx.fileSystem();
Future<Void> fut1 = Future.future(); Future<Void> fut1 = Future.future();
Future<Void> fut2 = Future.future(); Future<Void> fut2 = Future.future();
fs.createFile("/foo", fut1.handler()); fs.createFile("/foo", fut1.completer());
fut1.compose(string -> { fut1.compose(string -> {
fs.writeFile("/foo", Buffer.buffer(), fut2.handler()); fs.writeFile("/foo", Buffer.buffer(), fut2.completer());
}, fut2); }, fut2);
fut2.compose(integer -> { fut2.compose(integer -> {
fs.move("/foo", "/bar", startFuture.handler()); fs.move("/foo", "/bar", startFuture.completer());
}, startFuture); }, startFuture);
---- ----


Expand Down
12 changes: 5 additions & 7 deletions src/main/java/examples/CoreExamples.java
Expand Up @@ -18,9 +18,7 @@


import io.vertx.core.*; import io.vertx.core.*;
import io.vertx.core.buffer.Buffer; import io.vertx.core.buffer.Buffer;
import io.vertx.core.file.AsyncFile;
import io.vertx.core.file.FileSystem; import io.vertx.core.file.FileSystem;
import io.vertx.core.file.OpenOptions;
import io.vertx.core.http.HttpServer; import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest; import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse; import io.vertx.core.http.HttpServerResponse;
Expand Down Expand Up @@ -90,10 +88,10 @@ String blockingMethod(String str) {


public void exampleFuture1(HttpServer httpServer, NetServer netServer) { public void exampleFuture1(HttpServer httpServer, NetServer netServer) {
Future<HttpServer> httpServerFuture = Future.future(); Future<HttpServer> httpServerFuture = Future.future();
httpServer.listen(httpServerFuture.handler()); httpServer.listen(httpServerFuture.completer());


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


CompositeFuture.all(httpServerFuture, netServerFuture).setHandler(ar -> { CompositeFuture.all(httpServerFuture, netServerFuture).setHandler(ar -> {
if (ar.succeeded()) { if (ar.succeeded()) {
Expand Down Expand Up @@ -123,12 +121,12 @@ public void exampleFuture3(Vertx vertx, Future<Void> startFuture) {
Future<Void> fut1 = Future.future(); Future<Void> fut1 = Future.future();
Future<Void> fut2 = Future.future(); Future<Void> fut2 = Future.future();


fs.createFile("/foo", fut1.handler()); fs.createFile("/foo", fut1.completer());
fut1.compose(string -> { fut1.compose(string -> {
fs.writeFile("/foo", Buffer.buffer(), fut2.handler()); fs.writeFile("/foo", Buffer.buffer(), fut2.completer());
}, fut2); }, fut2);
fut2.compose(integer -> { fut2.compose(integer -> {
fs.move("/foo", "/bar", startFuture.handler()); fs.move("/foo", "/bar", startFuture.completer());
}, startFuture); }, startFuture);
} }


Expand Down
55 changes: 55 additions & 0 deletions src/main/java/io/vertx/core/CompositeFuture.java
Expand Up @@ -20,6 +20,9 @@
import io.vertx.core.impl.CompositeFutureImpl; import io.vertx.core.impl.CompositeFutureImpl;


/** /**
* The composite future wraps a list of {@link Future futures}, it is useful when several futures
* needs to be coordinated.
*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a> * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/ */
@VertxGen @VertxGen
Expand All @@ -36,18 +39,30 @@ static <T1, T2> CompositeFuture all(Future<T1> f1, Future<T2> f2) {
return CompositeFutureImpl.all(f1, f2); return CompositeFutureImpl.all(f1, f2);
} }


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


/**
* Like {@link #all(Future, Future)} but with 4 futures.
*/
static <T1, T2, T3, T4> CompositeFuture all(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4) { 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); return CompositeFutureImpl.all(f1, f2, f3, f4);
} }


/**
* Like {@link #all(Future, Future)} but with 5 futures.
*/
static <T1, T2, T3, T4, T5> CompositeFuture all(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5) { 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); return CompositeFutureImpl.all(f1, f2, f3, f4, f5);
} }


/**
* Like {@link #all(Future, Future)} but with 6 futures.
*/
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) { 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); return CompositeFutureImpl.all(f1, f2, f3, f4, f5, f6);
} }
Expand All @@ -63,35 +78,75 @@ static <T1, T2> CompositeFuture any(Future<T1> f1, Future<T2> f2) {
return CompositeFutureImpl.any(f1, f2); return CompositeFutureImpl.any(f1, f2);
} }


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


/**
* Like {@link #any(Future, Future)} but with 4 futures.
*/
static <T1, T2, T3, T4> CompositeFuture any(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4) { 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); return CompositeFutureImpl.any(f1, f2, f3, f4);
} }


/**
* Like {@link #any(Future, Future)} but with 5 futures.
*/
static <T1, T2, T3, T4, T5> CompositeFuture any(Future<T1> f1, Future<T2> f2, Future<T3> f3, Future<T4> f4, Future<T5> f5) { 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); return CompositeFutureImpl.any(f1, f2, f3, f4, f5);
} }


/**
* Like {@link #any(Future, Future)} but with 6 futures.
*/
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) { 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); return CompositeFutureImpl.any(f1, f2, f3, f4, f5, f6);
} }


@Override @Override
CompositeFuture setHandler(Handler<AsyncResult<CompositeFuture>> handler); CompositeFuture setHandler(Handler<AsyncResult<CompositeFuture>> handler);


/**
* Returns a cause of a wrapped future
*
* @param index the wrapped future index
*/
Throwable cause(int index); Throwable cause(int index);


/**
* Returns true if a wrapped future is succeeded
*
* @param index the wrapped future index
*/
boolean succeeded(int index); boolean succeeded(int index);


/**
* Returns true if a wrapped future is failed
*
* @param index the wrapped future index
*/
boolean failed(int index); boolean failed(int index);


/**
* Returns true if a wrapped future is completed
*
* @param index the wrapped future index
*/
boolean isComplete(int index); boolean isComplete(int index);


/**
* Returns the result of a wrapped future
*
* @param index the wrapped future index
*/
<T> T result(int index); <T> T result(int index);


/**
* @return the number of wrapped future
*/
int size(); int size();


} }
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/Future.java
Expand Up @@ -167,7 +167,7 @@ default <U> void compose(Handler<T> handler, Future<U> next) {
/** /**
* @return an handler completing this future * @return an handler completing this future
*/ */
Handler<AsyncResult<T>> handler(); Handler<AsyncResult<T>> completer();


static FutureFactory factory = ServiceHelper.loadFactory(FutureFactory.class); static FutureFactory factory = ServiceHelper.loadFactory(FutureFactory.class);


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/impl/CompositeFutureImpl.java
Expand Up @@ -215,7 +215,7 @@ private Handler<AsyncResult<CompositeFuture>> setSucceeded() {
} }


@Override @Override
public Handler<AsyncResult<CompositeFuture>> handler() { public Handler<AsyncResult<CompositeFuture>> completer() {
return this; return this;
} }


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/impl/FutureImpl.java
Expand Up @@ -125,7 +125,7 @@ public void handle(Future<T> ar) {
} }


@Override @Override
public Handler<AsyncResult<T>> handler() { public Handler<AsyncResult<T>> completer() {
return this; return this;
} }


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/package-info.java
Expand Up @@ -303,7 +303,7 @@
* {@link examples.CoreExamples#exampleFuture1} * {@link examples.CoreExamples#exampleFuture1}
* ---- * ----
* *
* The handler returned by {@link io.vertx.core.Future#handler()} completes the future. * The handler returned by {@link io.vertx.core.Future#completer()} completes the future.
* *
* {@link io.vertx.core.CompositeFuture#any} takes several futures arguments (up to 6) and returns a future that is * {@link io.vertx.core.CompositeFuture#any} takes several futures arguments (up to 6) and returns a future that is
* _failed_ when all the futures are and _succeeded_ otherwise: * _failed_ when all the futures are and _succeeded_ otherwise:
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/vertx/test/core/FutureTest.java
Expand Up @@ -160,7 +160,7 @@ public void testResolveFutureToHandler() {
handler.handle(Future.succeededFuture("the-result")); handler.handle(Future.succeededFuture("the-result"));
}; };
Future<String> fut = Future.future(); Future<String> fut = Future.future();
consumer.accept(fut.handler()); consumer.accept(fut.completer());
assertTrue(fut.isComplete()); assertTrue(fut.isComplete());
assertTrue(fut.succeeded()); assertTrue(fut.succeeded());
assertEquals("the-result", fut.result()); assertEquals("the-result", fut.result());
Expand All @@ -173,7 +173,7 @@ public void testFailFutureToHandler() {
handler.handle(Future.failedFuture(cause)); handler.handle(Future.failedFuture(cause));
}; };
Future<String> fut = Future.future(); Future<String> fut = Future.future();
consumer.accept(fut.handler()); consumer.accept(fut.completer());
assertTrue(fut.isComplete()); assertTrue(fut.isComplete());
assertTrue(fut.failed()); assertTrue(fut.failed());
assertEquals(cause, fut.cause()); assertEquals(cause, fut.cause());
Expand Down

0 comments on commit 9b6bbec

Please sign in to comment.