Skip to content

Instantly share code, notes, and snippets.

@siddharthray
Last active May 12, 2018 19:06
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 siddharthray/42838b39578be65c5f101e87f5dd6986 to your computer and use it in GitHub Desktop.
Save siddharthray/42838b39578be65c5f101e87f5dd6986 to your computer and use it in GitHub Desktop.
JavaScript Promise
var calculationPromise = new Promise(function(resolve,reject){
setTimeout(function() {
resolve(1+1);
}, 1000)
});
var calculationPromise2 = new Promise(function(resolve,reject){
setTimeout(function() {
resolve(2+2);
}, 500)
});
function addTwo(value){
return value * 2;
};
function printFinalValue(nextValue) {
console.log('the final value is '+ nextValue);
}
calculationPromise
.then(addTwo)
.then(printFinalValue);
calculationPromise2
.then(addTwo)
.then(printFinalValue);
var calculationPromise = new Promise(function(resolve, reject){
setTimeout(function (){
resolve(1+1);
},1000)
});
function addTwo(value) {
return value + 2;
};
function printFinalValue (nextValue) {
console.log('The final value is', nextValue);
}
calculationPromise
.then(addTwo)
.then(printFinalValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment