Created
September 12, 2017 07:00
-
-
Save anonymous/2d98efe39c61a6f744e627556e88de45 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 asyncFunc() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
const result = Math.random(); | |
result > 0.5 ? resolve(result) : reject('Oppps....I cannot calculate') | |
}, 1) | |
}); | |
} | |
for (let i=0; i<10; i++) { | |
asyncFunc() | |
.then(result => console.log('Result is: ' + result)) | |
.catch(result => console.log('Error: ' + result)) | |
} |
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
Result is: 0.7930997430022211 | |
Error: Oppps....I cannot calculate | |
Result is: 0.6412258210597288 | |
Result is: 0.7890325910244533 | |
Error: Oppps....I cannot calculate | |
Error: Oppps....I cannot calculate | |
Result is: 0.8619834683310168 | |
Error: Oppps....I cannot calculate | |
Error: Oppps....I cannot calculate | |
Result is: 0.8258410427354488 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment