Last active
May 12, 2018 19:06
-
-
Save siddharthray/42838b39578be65c5f101e87f5dd6986 to your computer and use it in GitHub Desktop.
JavaScript Promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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