Introduction
The previous chapter got you started on promises in TypeScript. While promises improved our ability to write asynchronous code without the ugliness of nested callbacks, developers still wanted a better way to write asynchronous code. The promise syntax is sometimes challenging for programmers with a background in the C family of languages, and so the "syntactic sugar" of async
/await
was proposed to be added to the ECMAScript specification.
In this chapter, we'll learn about the introduction of new asynchronous programming paradigms to the ECMAScript standard, examine the syntax, and look at their use in TypeScript. We'll also cover the new (as of the time of writing) top-level await
feature, which allows asynchronous programming outside of an async
function. We will again look at error handling in asynchronous programming and examine the pros and cons of using async
/await
syntax versus promises.
Readers who have been through the prior chapter...