In the previous section, we introduced the callback pattern as a way to deal with asynchronous calls. The pattern offers a structured way of dealing with such calls, in that we can always know what to expect in its method signature; the error is the first parameter, the second parameter is the response, and so on. But the pattern does have its shortcomings. The shortcomings might not be obvious at first, because you might only call the code like this:
openFile('filename', (err, content) => {
console.log( content );
statement4;
statement5;
})
statement2;
statement3
What we see here is how we invoke the method openFile(). Once that runs to completion, the callback is called and, inside of the callback, we continue invoking statement4 and statement5.
This looks okay in the sense that it is still readable. The...