Skip to content

Instantly share code, notes, and snippets.

@rice10t
Created June 3, 2016 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rice10t/97c366352bf6416748136c2448d34e6b to your computer and use it in GitHub Desktop.
Save rice10t/97c366352bf6416748136c2448d34e6b to your computer and use it in GitHub Desktop.
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