chapter eight

8 Linear async flows

 

This chapter covers

  • The Node.js architecture at a glance
  • Fundamentals of the JavaScript Promise API
  • Stitching together promise chains
  • Promise combinators
  • Benefits of async/await
  • 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 has 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. In retrospect, JavaScript was probably not the right solution to this problem, but it has managed to keep its place as the language of the net. This responsibility meant that it had to continue to develop to live up to the situation - and it did!

Programming the web is very different from programming local servers, because you can not make assumptions about where the data is located. Is it in local storage, on the intranet or a million miles away? With distributed programming, latency time must always be taken into account.

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 with async/await

8.5   Async iteration

8.6   Top-level await

8.7   Summary