8 Linear async flows

 

This chapter covers

  • Reviewing a basic Node.js architecture
  • Working with the JavaScript Promise API
  • Assembling promise chains to model complex asynchronous flows
  • Using async/await and asynchronous iterators

For over a decade prophets have voiced the contention that the organization of a single computer has reached its limits and that truly significant advances can be made only by interconnection of a multiplicity of computers.

—Gene Amdahl

As Amdhal predicted, the web is a gigantic, distributed, interconnected network, and the language we use must rise to the challenge by providing appropriate abstractions that facilitate programming this ever-evolving and ever-changing web. Programming the web is different from programming local servers, because you can’t make assumptions about where the data is located. Is it in local storage, a cache, on the intranet, or a million miles away? Hence, one of the main design goals of JavaScript is that it needs to have strong abstractions for asynchronous data operations.

8.1 Architecture at a glance

8.2 JavaScript as promised

8.2.1 Principle of data locality

8.2.2 Are promises algebraic?

8.2.3 Fluent chaining

8.2.4 Promises in the wild

8.3 API review: Promise combinators

8.3.1 Promise.all

8.3.2 Promise.race

8.3.3 Promise.allSettled

8.3.4 Promise.any

8.4 async made easy

8.5 async iteration

8.6 Top-level await

Summary