Promises

Async-await

async function run () {
  const user = await getUser()
  const tweets = await getTweets(user)
  return [user, tweets]
}

async functions are another way to use functions. See: Async Function

Promise function

Promise.all(···)
Promise.race(···)
Promise.reject(···)
Promise.resolve(···)

Using Promises in finally

promise
  .then((result) => { ··· })
  .catch((error) => { ··· })
  .finally(() => {
    /\*logic independent of success/error \*/
  })

The handler is called when the promise is fulfilled or rejected

Using Promises

promise
  .then((result) => { ··· })
  .catch((error) => { ··· })

make the commitment

new Promise((resolve, reject) => {
  if (ok) { resolve(result) }
  else { reject(error) }
})

for asynchronous programming. See: Promises

Comments