An Example Promise
function myAsyncFunction(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
});
}
You pass executor two functions, resolve and reject.
Resolve is your success handler, and its return value is passed to any following then block.
Reject is your failure handler, and its return value is passed to any following catch block.