Chapter 9. Asynchronous programming with callbacks and futures
This chapter covers
- The nonblocking async programming model
- Callbacks for asynchronous APIs
- Improving asynchronous readability with futures and completers
- Unit-testing asynchronous code
In web programming, you can’t rely on events outside your application’s control happening in a specific order. In the browser, retrieving data from a server might take longer than you expect, and instead of waiting for the data, a user might click another button. A Dart server application will likely need to handle a new request for data before a previous request has finished reading data from the file system. This type of programming is known as an asynchronous model (async), and its counterpart is the synchronous model. In a synchronous model, everything happens in order, waiting for the previous step to fully complete. This is fine for some environments, but in a web application environment, you can’t block all execution while you wait for the previous task to complete.