I am reading a book on Vert.x. At one point it compares 2 code snippets, one using Vert.x's Future and other one using Vert.x's RxJava API. Code basically fetches data from a database and processes result-set to map rows to objects. Comparing 2 approaches, it states:
However, while Futures make the code a bit more declarative, we are retrieving all the rows in one batch and processing them. This result can be huge and take a lot of time to be retrieved. At the same time, you don’t need the whole result to start processing it. We can process each row one by one as soon as you have them. Fortunately, Vert.x provides an answer to this development model challenge and offers you a way to implement reactive microservices using a reactive programming development model. Vert.x provides RxJava APIs to:
• Combine and coordinate asynchronous tasks
• React to incoming messages as a stream of input
In addition to improving readability, reactive programming allows you to subscribe to a stream of results and process items as soon as they are available. With Vert.x you can choose the development model you prefer. In this report, we will use both callbacks and RxJava.
I am not sure how RxJava API approach is better here. Database would send all rows once and not one by one(assuming we are fetching data from traditional relational database). So in RxJava based approach too we would have to wait for entire result set to arrive over the network,and then only we can process them.