I got a pretty small Verticle that should connect to a database and regularly poll a table and send the objects to the event bus. Thus far I can connect to the database, but the handler afterwards gets not executed and my polling timer does not start. I guess it's something obvious and appreciate every help.
I use Vert.x 3.8 Promises as Futures are deprecated (just like in the example behind that link). As you can see in my code, using deprecated Futures works just fine! But who want's to use deprecated code, heh? Either I'm doing something wrong or that's a bug in Vert.x, what I don't assume.
My Vert.x is at 3.8.1
class JdbcVerticle extends AbstractVerticle {
private SQLConnection connection
@Override
void start(Promise<Void> startPromise) {
def jdbcParams = config().getJsonObject('connection')
// This gets executed:
testFuture().handler = { println "Test Future handler runs!" }
// This is never executed :-(
connect(jdbcParams).handler = { println "Connected..." }
}
Future<Void> connect(JsonObject jdbcParams) {
def promise = Promise.<Void>promise()
def client = JDBCClient.createShared(vertx, jdbcParams)
client.getConnection() { connection ->
if(connection.failed()) {
promise.fail(connection.cause())
} else {
this.connection = connection.result()
promise.complete()
}
}
return promise.future()
}
Future<Void> testFuture() {
def future = Future.<Void>future()
vertx.setTimer(200) { future.complete() }
return future
}
}