Future.complete() not blocking

618 views
Skip to first unread message

Piero dS

unread,
Sep 28, 2016, 12:41:30 PM9/28/16
to vert.x
This code does not block and just goes through:

Future<String> f = Future.future();
       
f.result();


How do I know when my future is complete then if result() does not block before Future.complete() is called?

Thomas SEGISMONT

unread,
Sep 28, 2016, 12:45:40 PM9/28/16
to ve...@googlegroups.com
Vert.x futures are not Java futures. You need to call setHandler to register a callback. This is how you get notified of completion.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/751efe73-e694-4774-84fd-cd34388b3b6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clement Escoffier

unread,
Sep 28, 2016, 12:46:10 PM9/28/16
to ve...@googlegroups.com
Hi,

Yes, Vert.x futures are not blocking. You need to attach a handler called when the future is completed (successfully or not):

Future<String> f = Future.future();
f.setHandler(ar -> {
  if (ar.failed()) {
    Throwable cause = ar.cause(); => the failure
  } else {
   String result = ar.result();
});

Then, later in the code, you will do something like:

f.complete(“Hello”); 

or

f.fail(“my bad !”); // or f.fail(exception);

Clement


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Piero dS

unread,
Sep 28, 2016, 12:47:43 PM9/28/16
to vert.x
:) thanks


On Wednesday, September 28, 2016 at 6:45:40 PM UTC+2, Thomas Segismont wrote:
Vert.x futures are not Java futures. You need to call setHandler to register a callback. This is how you get notified of completion.
2016-09-28 18:41 GMT+02:00 Piero dS <dslp...@gmail.com>:
This code does not block and just goes through:

Future<String> f = Future.future();
       
f.result();


How do I know when my future is complete then if result() does not block before Future.complete() is called?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Piero dS

unread,
Sep 29, 2016, 6:09:01 AM9/29/16
to vert.x
Two more questions...

1 what is a completer?
2 how do you pass the result of a Future to the next Future?

Thanks

Thomas SEGISMONT

unread,
Sep 29, 2016, 6:25:24 AM9/29/16
to ve...@googlegroups.com
2016-09-29 12:09 GMT+02:00 Piero dS <dslp...@gmail.com>:
Two more questions...

1 what is a completer?


"You can use completer that completes a future with the operation result or failure. It avoids having to write the traditional: if success then complete the future else fail the future."
 
2 how do you pass the result of a Future to the next Future?


You might also have a look at Future#map to transform the data
 
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages