This chapter covers
- Callbacks and their limitations, as shown with a gateway/edge service example
- Futures and promises--a simple model to chain asynchronous operations
- Reactive extensions--a more powerful model that is especially well suited to composing streams of asynchronous events
- Kotlin coroutines--language-level support for asynchronous code execution flows
You will need to write all sorts of business logic while developing a reactive application, and not all logic is easy to express in an asynchronous form. While callbacks are a simple form of asynchronous event notification, they can easily render asynchronous code complicated.
Let’s look at a real example of why callbacks are not always the best asynchronous programming model. Then we’ll explore the multiple options supported in Vert.x.
We’ll take the example of an edge service to illustrate composing asynchronous operations with different asynchronous programming models.
An edge service is also frequently called an API gateway. It is a service that serves as a facade for other services, so that a requester just has to deal with one service interface rather than having to talk to each service. An edge service may also perform other tasks, such as data transformation and interacting with other services, so it does not just conveniently aggregate data from multiple services.