Skip to content

Instantly share code, notes, and snippets.

@0632347878
Created March 9, 2019 20:34
Show Gist options
  • Save 0632347878/b311f7cbb034ad163ffefc2e44eb9361 to your computer and use it in GitHub Desktop.
Save 0632347878/b311f7cbb034ad163ffefc2e44eb9361 to your computer and use it in GitHub Desktop.
/* ES5, using Bluebird */
var isMomHappy = false;
// Promise
var willIGetNewPhone = new Promise(
function (resolve, reject) {
if (isMomHappy) {
var phone = {
brand: 'Samsung',
color: 'black'
};
resolve(phone);
} else {
var reason = new Error('mom is not happy');
reject(reason);
}
}
);
// call our promise
var askMom = function () {
willIGetNewPhone
.then(function (fulfilled) {
// yay, you got a new phone
console.log(fulfilled);
})
.catch(function (error) {
// ops, mom don't buy it
console.log(error.message);
});
}
askMom();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment