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.

9.1. Why web apps should be asynchronous

9.2. Using callbacks with async programming

9.3. Introducing the Future and Completer pair

9.4. Unit-testing async APIs

9.5. Summary

sitemap