ES8 async/await functions

Now let’s look at the newest iteration of asynchronous solutions in JS the async/await function.

The async function declaration defines an asynchronous function, which returns an AsyncFunction object.

When an async function is called, it returns a Promise . When the async function returns a value, the Promise will be resolved with the returned value. When the async function throws an exception or some value, the Promise will be rejected with the thrown value.

An async function can contain an await expression, that pauses the execution of the async function and waits for the passed Promise 's resolution, and then resumes the async function's execution and returns the resolved value.

Let’s look at some code:

In this example you will see STANDARD PROMISE in action followed by the same code implemented with ASYNC/AWAIT