Skip to content

Instantly share code, notes, and snippets.

@danielsan
Created May 25, 2018 16:07
Show Gist options
  • Save danielsan/c853d3c62fc48f84a767632712f1deab to your computer and use it in GitHub Desktop.
Save danielsan/c853d3c62fc48f84a767632712f1deab to your computer and use it in GitHub Desktop.
Promise.all example
const createAPromise = s => new Promise((resolve) => {
console.log(`this promise will resolve in ${s} seconds`);
setTimeout(() => {
resolve(s);
console.log(`promise solved after ${s} seconds`);
}, s * 1000);
});
const promises = [];
for (let i = 10; i--;) promises.push(createAPromise(i + 1));
Promise.all(promises).then((allResults) => {
console.log('All promises have been resolved', allResults);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment