Chapter 8. Managing asynchronous events and data

 

This chapter covers

  • Identifying the challenges of writing asynchronous code
  • Avoiding the use of nested callbacks through functional techniques
  • Streamlining asynchronous code using promises
  • Generating data lazily with function generators
  • Introducing reactive programming
  • Applying reactive programming to tackle event-driven code

Functional programmers argue that there are great material benefits—that a functional programmer is an order of magnitude more productive than his conventional counterpart, because functional programs are an order of magnitude shorter.

John Hughes, “Why Functional Programming Matters”[1]

1 From Research Topics in Functional Programming,” ed. D. Turner (Addison-Wesley, 1990), 17–42, http://mng.bz/Zr02.

Until now, you’ve been learning how to think functionally and using functional techniques to write, test, and optimize your JavaScript code. All of these techniques are designed to tame the complexities intrinsic to mid- and large-scale web applications, which can easily become increasingly difficult to maintain. Many years ago, interaction with web applications was limited to submitting large forms and rendering entire pages at once. Applications have evolved, and with them the demands of users. Nowadays, we all expect pages to behave more like native applications that respond and react in real time.

8.1. Challenges of asynchronous code

8.2. First-class asynchronous behavior with promises

8.3. Lazy data generation

8.4. Functional and reactive programming with RxJS

8.5. Summary