Глоссарий

Promise / async-await

Promise — объект, представляющий результат асинхронной операции: pending (выполняется), fulfilled (успешно) или rejected (ошибка). async/await — синтаксический сахар для удобной работы с Promise.

Promise

fetch('/api/users')
  .then(res => res.json())
  .then(users => console.log(users))
  .catch(err => console.error(err));

async/await

async function getUsers() {
  try {
    const res = await fetch('/api/users');
    const users = await res.json();
    console.log(users);
  } catch (err) {
    console.error(err);
  }
}

Promise.all vs Promise.allSettled