Created
August 18, 2016 19:32
-
-
Save jaredatron/f8196a7f558e031766335d694779ce30 to your computer and use it in GitHub Desktop.
promises.js
This file contains 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
const runLater = function(milliseconds){ | |
return new Promise(function(resolve, reject){ | |
setTimeout(function(){ resolve('a'); }, milliseconds); | |
}) | |
} | |
runLater(2000).then(function(string){ | |
string += 'b' | |
console.log(string) | |
return string | |
}).then(function(string){ | |
string += 'c' | |
console.lo(string) | |
return string | |
}) | |
.catch(function(error){ | |
console.log('ERROR:', error) | |
// return 'Z' | |
throw new Error('zomg cjheeeeze') | |
}) | |
.then(function(string){ | |
string += 'd' | |
console.log(string) | |
return string | |
}).then(function(string){ | |
string += 'e' | |
console.log(string) | |
return string | |
}).then(function(string){ | |
string += 'f' | |
console.log(string) | |
return string | |
}).catch(function(error){ | |
console.log('ERROR:', error) | |
}) | |
// runLater(1000).then(function(){ | |
// console.log('B') | |
// }).catch(function(){ | |
// console.log('B ERROR') | |
// }) | |
// runLater(3000).then(function(){ | |
// console.log('C') | |
// }).catch(function(){ | |
// console.log('C ERROR') | |
// }) | |
// // setTimeout(function() { | |
// // console.log('A') | |
// // }, 2000); | |
// // setTimeout(function() { | |
// // console.log('B') | |
// // }, 1000); | |
// // setTimeout(function() { | |
// // console.log('C') | |
// // }, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment