Vert.x - Promise/Future

> Procedural Languages > Java > Java - Vert.X Framework

1 - About

promise and future in Vert.x

Vert.x futures are not JDK futures, they can be

  • composed
  • and queried in a non-blocking fashion.

They shall be used for simple coordination of asynchronous tasks, and especially those of:

  • deploying verticles
  • and checking if they were successfully deployed or not.
Advertising

3 - Example

with the start method of a verticle, prepare the database, then start the webserver

@Override
public void start(Promise<Void> promise) throws Exception {
	Future<Void> steps =
	  prepareDatabase()
	  .compose(v -> startHttpServer());
	steps.setHandler(promise);
}

4 - Management

4.1 - Creation

Promise<Void> promise = Promise.promise();

5 - Documentation