At the beginning…
Vertx introduce the concept of verticle. Each statements in a verticle use an event loop. You can define many verticles to interact with the same event loop. But, a verticle can run in another thread and executed concurrently or not from the worker pool.
Thread pool management is the biggest difference between Vert.x and Node.js, except for polyglot. Vert.x creates Run Loops (Event Loops) equaling the number of cores and provides thread pool-related function to handle tasks using server resources requiring long periods for event handling.
So, let’s talk about our Future !
Vertx is inspired by Node JS and use callback to make asynchronous functions.(you can use RxJava programming style if you don’t like callbacks) Vertx provide interfaces to handle asynchronous result from callbacks and define callbacks. But, it also provide a smart system to prevent callback hell situations !
Interface Future<T> provide by Vertx
Considere this fictional exampel. I want to save a specific data in my database before data updating. So i have a class (which extends AbstractVerticle) with an attribute called databaseClient which provide a database connection. (using an object which implements SQLConnection interface) Methods queryWithParams and updateWithParams are provided by SQLCommon library of Vertx.
So, in this example, updateUserData is called after saveDataToHistoryTable execution. We don’t need to call updateUserData in saveDataToHistoryTable function. (and create callback hell situation !)
Pretty simple ? :)
Vertx has a big potential and probably, a great rival for Node JS. I’ll probably write some drafts about this complete toolkit.
See you soon for another asynchronous programming technologies !