Chapter 9. Asynchronous data
This chapter covers
- Handling data asynchronously
- Scheduling asynchronous tasks
- Streaming HTTP responses
- Unidirectional communication with Comet
- Bidirectional communication with WebSockets
In this chapter, we’ll learn how to process data asynchronously and how to schedule asynchronous jobs. First, we’ll get familiar with the principle behind asynchronous data handling and why it’s useful. One of the goals of handling data asynchronously is allowing our application to scale to thousands of concurrent connections, while responding to clients immediately. Then we’ll learn about an older but widely used protocol to handle data asynchronously between servers and clients: Comet. We’ll finish with the WebSocket protocol, which is a standard way to communicate data asynchronously between servers and clients.
This is a long chapter, as we’re going to try to cover most of the aspects of Play 2’s asynchronous feature. But because this is an essential Play 2 feature, it’s worth it.
Before we start, a little introduction to asynchronous data is useful.