The async and await Keywords3:55 with Jay McGavren
In the previous video, we showed you how to use the `then` method on the promises returned by various Selenium WebDriver methods. But the resulting code was kind of a mess. In this video, we'll show you a better way to handle those promises, a way that we'll use for the rest of this course.
In this video, we'll be using this version of the RSVP site.
In the previous video, we showed you how to use the
then method on the promises returned by various Selenium WebDriver methods. But the resulting code was kind of a mess. In this video, we'll show you a better way to handle those promises, a way that we'll use for the rest of this course.
Node.js supports the
async marks a function as asynchronous. Within asynchronous functions, you can use the
await keyword before function calls that return a promise.
await waits for the promise to resolve, then return's the promise's resulting value. It's a much cleaner way to write code that uses promises.
If we return to the terminal and run
mocha, we'll get the same result.
This code looks a lot cleaner, right?
await will be everywhere soon. The Selenium maintainers are strongly encouraging developers to start using them, so now's the time to switch.
You need to sign up for Treehouse in order to download course files.Sign up