Vert.x - Promise/Future

Java Conceptuel Diagram

About

promise and future in Vert.x

Do not confuse futures with promises.

  • futures represent the “read-side” of an asynchronous result,
  • promises represent the “write-side”.

They allow you to defer the action of providing a result. In most cases, you don’t need to create promises yourself in a Vert.x application.

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.

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);
}

Management

Creation

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

Documentation





Discover More
Java Conceptuel Diagram
Vert.x - Blocking Code

This page is blocking code in Vert.x that will block the event loop. By default, blocking code is executed on the Vert.x worker pool. promise can be composed, the database start first, then the...
Java Conceptuel Diagram
Vert.x - Verticle

Verticles are the technical units of deployments of code in Vert.x. Verticles share certain similarities with actors in the actor model. Verticles communicate with each other by generating messages...



Share this page:
Follow us:
Task Runner