chapter eight

8 Linear async flows

 

This chapter covers

  • The Node.js architecture at a glance
  • Fundamentals of the JavaScript Promise API
  • Promise chains and combinators
  • Benefits of async/await and async 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 network, and the language we use must rise to the challenge and provide appropriate abstractions that facilitate programming for this ever evolving and changing web. Programming the web is very 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 data-locality.

8.1   Architecture at a glance

8.2   JavaScript as promised

8.2.1   Principle of non-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

8.7   Summary