Created
June 3, 2016 01:35
-
-
Save rice10t/97c366352bf6416748136c2448d34e6b 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
const promise = () => { | |
const randomNum = Math.floor(Math.random() * 1000); | |
console.log('created: ' + randomNum); | |
return new Promise(resolve => { | |
setTimeout( | |
resolve.bind(this, randomNum), | |
randomNum | |
); | |
}); | |
} | |
const show = value => { | |
console.log(value); | |
return value; | |
} | |
const calc = value => { | |
console.log('Stopped'); | |
console.log(Date.now() - startTime + 'ms'); | |
} | |
console.log('Started'); | |
const startTime = Date.now(); | |
console.log('Creating Promises'); | |
const promises = [promise(), promise(), promise()]; | |
console.log('Promises Created'); | |
Promise.all(promises).then(show).then(calc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment