Chapter 4. Asynchronous Control Flow Patterns with ES2015 and Beyond
In the previous chapter, we learned how to deal with asynchronous code using callbacks and how they can have a bad impact on our code, generating issues such as callback hell. Callbacks are the building blocks of asynchronous programming in JavaScript and in Node.js, but over the years, other alternatives have emerged. Those alternatives are more sophisticated in order to be able to deal with asynchronous code in ways that are more convenient.
In this chapter, we are going to explore some of the most famous alternatives, promises and generators. We will also explore async await, an innovative syntax that will be available in JavaScript as part of the release of ECMAScript 2017.
We will see how these alternatives can simplify the way we deal with asynchronous control flows. Finally, we will compare all these approaches in order to understand all the pros and cons of each of them and be able to wisely choose...