I'm implementing a JAX-RS Service in an Application Server using Vert.x to store data in combination with Vert.x Pg pool. Storing data is quite straightforward as there's nothing to return to the client. However when it comes to a HTTP GET Request it becomes more complex.
For example:
public List<Data> findAll() {
List<Data> list = new ArrayList<>();
pool.query("SELECT * FROM DATA", ar -> {
if (ar.succeeded()) {
RowSet rows = ar.result();
for (Row row : rows) {
list.add(new Data(row.getString(0), row.getString(1)));
}
} else {
System.out.println("Failure: " + ar.cause().getMessage());
}
});
return list;
}
So, as you can see, being "ar" a io.vertx.core.AsyncResult it returns immediately, with an empty ArrayList. I understand I should return an AsyncResult or a subclass of it, just I don't have an idea how could the client get the List of objects, when the query completed. Any idea / example? Thanks!