Overview

let promise = new Promise(function(resolve, reject) {
  // Executor (the producing code)
});
let promise = new Promise(function(resolve, reject) {
	if (true) {
		setTimeout(() => resolve("done"), 1000);
	} else {
		setTimeout(() => reject(new Error("Error!")), 1000);
	}  
});
let promise = new Promise(function(resolve, reject) {
  resolve("done");
  reject(new Error("…")); // ignored
  setTimeout(() => resolve("…")); // ignored
});

Consumers: then, catch, finally

then

promise.then(
  function(result) { /* handle a successful result */ },
  function(error) { /* handle an error */ }
);
let promise = new Promise(function(resolve, reject) {
  setTimeout(() => resolve("done!"), 1000);
});

promise.then(
  result => console.log(result), // shows "done!" after 1 second
  error => console.log(error) // doesn't run
);
promise.then(alert);

catch