Jordan Savant # Software Engineer

// this is a function that returns a promise
// just like an async function would
// it does immediate work and then setTimeout
const doSomethingAsync = () => {
  return new Promise(resolve => {
    console.log("in doSomethingAsync new Promise")
    setTimeout(() => resolve('I did something'), 1000)
  })
}

// any function defined as async is actually
// returning a promise and executing immediately
// the returned data is the same as the data passed to resolve
// and throwing errors is how to reject data
const doSomething = async () => {
  console.log("doSomething")
  // because this function is marked as async, it runs asynchronously
  let r = await doSomethingAsync()
  console.log("r", r)
}

console.log('before')
doSomething()
console.log('after')