Design pattern for callback hell in Vert.x 3

836 views
Skip to first unread message

poiuytrez

unread,
Jun 18, 2015, 11:19:59 AM6/18/15
to ve...@googlegroups.com
Hello, 

I am writing a web application. I am currently writing a module which:
1. load a first file (blocking)
2. based on this results, load a second file (blocking)

What is the is best way to handle this chain of callbacks? Should I call 2 times vertx.executeBlocking?

Thank you for your help.

PS : I have never used Vert.x 2

Tim Fox

unread,
Jun 18, 2015, 11:31:55 AM6/18/15
to ve...@googlegroups.com
On 18/06/15 16:19, poiuytrez wrote:
Hello, 

I am writing a web application. I am currently writing a module which:
1. load a first file (blocking)
2. based on this results, load a second file (blocking)

What is the is best way to handle this chain of callbacks? Should I call 2 times vertx.executeBlocking?

If they're both blocking why not just put 1 and 2 in the same executeBlocking block?

Or you could use a worker verticle.

Thank you for your help.

PS : I have never used Vert.x 2
--
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.
For more options, visit https://groups.google.com/d/optout.

Ronald van Raaphorst

unread,
Jun 19, 2015, 9:37:05 AM6/19/15
to ve...@googlegroups.com
Have a look at the Java CompletableFutures. You can define several futures, complete them when you're done and then continue with the next future, or wait untill several futures are all completed.

Guillaume Charhon

unread,
Jun 19, 2015, 10:38:43 AM6/19/15
to ve...@googlegroups.com
Interesting.

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/WOotux-bL8k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.

Assen Todorov

unread,
Jun 21, 2015, 2:55:17 AM6/21/15
to ve...@googlegroups.com
Hi,

Look at this  -> https://github.com/baldinsystems/vertx-composition-example
Not really pattern, but this way you could execute chain of verticles without the callback hell ;-)

poiuytrez

unread,
Dec 10, 2015, 10:11:56 AM12/10/15
to vert.x
Some documentation written in August with Vert.x using CompletableFutures:

Ronald van Raaphorst

unread,
Dec 11, 2015, 3:56:15 AM12/11/15
to vert.x
You can also use the vertx-sync / quasar fibers to write non blocking async code. See http://vertx.io/docs/vertx-sync/java/


On Thursday, June 18, 2015 at 5:19:59 PM UTC+2, poiuytrez wrote:
Reply all
Reply to author
Forward
0 new messages