JSFiddle - React, Tailwind, and code Playground

by moogs

JavaScript

Promise.prototype.finally = function(cb) {
    const res = () => this;
    const fin = () => Promise.resolve(cb()).then(res);
    return this.then(fin, fin);
};

var explode = false;

var promise = new Promise(function(resolve, reject) {
    if (explode) {
      reject();
    } else {
      resolve();
    }
  }).then(() => console.log('Resolved'))
  .catch(() => console.log('Failed'))
  .finally(() => console.log('Always run this'));