concept Promise.all in category javascript

appears as: Promise.all
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

This is an excerpt from Manning's book Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond.

function loadCreditAndScore(userId) {
  return Promise.all(
    ajax(`/user/${userId}/credit_availability`),
    Promise.race(
      ajax(`/transunion/credit_score?user=${userId}`),
      ajax(`/equifax/credit_score?user=${userId}`)
    )
  )
}

loadCreditAndScore('4XJ').then(([creditAvailability, creditScore]) => {
  // Do something with credit availability and credit score
})
  • 1 Promise.all takes an array of promises and returns a single promise.