Skip to content

Instantly share code, notes, and snippets.

@blarzHernandez
Last active January 12, 2020 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blarzHernandez/2607707536c9853e121ee4206ce32f83 to your computer and use it in GitHub Desktop.
Save blarzHernandez/2607707536c9853e121ee4206ce32f83 to your computer and use it in GitHub Desktop.
//condition to resolve or reject the promise
const isDadHappy = false;
//Trumpet promise
const trumpet = {
brand: "Mendini",
model: "MTT-30L",
price: 125
};
//Creating the promise
const getMyTrumpet = new Promise((resolve, reject) => {
if (isDadHappy) {
resolve(trumpet);
} else {
const error = "Dad was not agree with my work";
reject(error);
}
});
/* He is gonna ask to Dad about the promise for the next days until December 24*/
const askToDad = () => {
getMyTrumpet
.then(trumpet => {
//Congrats my son. You got a really nice trumpet
console.log("Wow my trumpet is here", trumpet);
})
.catch(error => {
console.log("Error", error);
});
};
/*He is asking the same question every 3 seconds**/
setInterval(askToDad, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment