Created
January 12, 2018 15:19
-
-
Save wongni/f6aa4df00082d317c40ba457b0c767c3 to your computer and use it in GitHub Desktop.
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
function printLater (number) { | |
return new Promise( // return a new Promise | |
(resolve, reject) => { // Take resolve and reject as parameters | |
setTimeout(() => { | |
if (number > 5) { | |
// reject causes an error | |
return reject('number is greater than 5') | |
} | |
resolve(number + 1) // return number + 1 | |
console.log(number) | |
}, 1000) | |
} | |
) | |
} | |
printLater(1). | |
then(num => printLater(num)). | |
then(num => printLater(num)). | |
then(num => printLater(num)). | |
then(num => printLater(num)). | |
then(num => printLater(num)). | |
catch(e => console.log(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment