Summary
This chapter discussed how we can face asynchronous programming in JavaScript. Starting with the asynchronous nature of the JavaScript's runtime execution flow, we explored how to manage events using callback functions. We saw that, although callbacks are widely used to manage asynchronous code, they are not so effective. A heavy use of callbacks leads to unreadable code and the so-called callback hell—a maze of code difficult to read and understand. Moreover, managing asynchronous code with callbacks do not allows us to catch failures.
Promises can help us get more control on asynchronous code. We have seen the standard Promise's API of ECMAScript 6 and shown how to use them in order to catch results and failure and synchronize multiple asynchronous tasks.
Then, we approached the asynchronous code management using a technique based on Generators, a new feature of ECMAScript 6 as well. This approach allows us to manage asynchronous code by writing code in a synchronous style. This...