Vertx - Future Example
Table of Contents
CompletableFuture
CompletableFuture to wait that an execution finish.
CompletableFuture<Void> testDataLoaded = new CompletableFuture<>();
vertx
.executeBlocking(AppTest::loadTestData) // load test data
.onFailure(t -> {
Logger.error(t);
testDataLoaded.complete(null);
})
.onSuccess(appLoaded::complete);
try {
// wait, we make it wait because the class can be extended
// and the extension needs that the verticle has been deployed
testDataLoaded.get(60, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Logger.error(e);
}