Tip 44 Create Clean Functions with Async/Await

In this tip, you’ll learn how to streamline promises with async/await.

In the previous tip, you saw that promises are awesome. They’re a vast improvement over callbacks, but their interfaces are still a little clunky. You’re still working with callbacks in methods. Fortunately, the language continues to improve. You can now avoid callbacks entirely by adding asynchronous promise data to a variable in a single function.

Developers usually talk about the new syntax, async/await, as a group, but it’s really two separate actions. You use the async keyword to declare that an encapsulating function will be using asynchronous data. Inside the asynchronous function, you can use the await keyword ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.