Promise API

Promise.resolve

let promise = Promise.resolve(value);

// same
let promise = new Promise(resolve => resolve(value));

// example
function loadCached(url) {
  let cache = loadCached.cache || (loadCached.cache = new Map());

  if (cache.has(url)) {
    return Promise.resolve(cache.get(url)); // (*)
  }

  return fetch(url)
    .then(response => response.text())
    .then(text => {
      cache.set(url,text);
      return text;
    });
}

Promise.reject

Promise.all

Promise.allSettled

Promise.race

Last updated

Was this helpful?