Async/Await and Promises

Great example of async await functions working together with a promise.

by Kirubel Girma

JavaScript

async function f() {

  let promise = new Promise((resolve, reject) => {
    setTimeout(() => resolve("done!"), 5000)
  });

  let result = await promise; // wait until the promise resolves (*)

  alert(result); // "done!"
}

f();