Summary
In this chapter, we learned how to use promises and async/await syntax to write asynchronous code that is more concise, cleaner, and easier to read.
As we’ve seen, promises and async/await greatly simplify the serial execution flow, which is the most commonly used control flow. In fact, with async/await, writing a sequence of asynchronous operations is almost as easy as writing synchronous code. Running some asynchronous operations concurrently is also very easy thanks to Promise.all()
and Promise.allSettled()
.
But the advantages of using promises and async/await don’t stop here. We learned that they provide a transparent shield against tricky situations such as code with mixed synchronous/asynchronous behavior (a.k.a. Zalgo, which we discussed in Chapter 3, Callbacks and Events). On top of that, error management with promises and async/await is much more intuitive and leaves less room for mistakes (such as forgetting to forward errors, which is a serious...