Skip to content

Instantly share code, notes, and snippets.

@sunkibaek
Last active December 16, 2017 02:01
Show Gist options
  • Save sunkibaek/9d73efc9f71ed52bd1e422c33f28a9fb to your computer and use it in GitHub Desktop.
Save sunkibaek/9d73efc9f71ed52bd1e422c33f28a9fb to your computer and use it in GitHub Desktop.
Promise all with timeout
const timedPromise = () => {
return new Promise((resolve, reject) => {
console.log('promise1 started');
setTimeout(() => {
resolve('promise1')
}, 3000);
});
}
const promise2 = Promise.resolve('promise2');
const allPromises = [];
[timedPromise(), promise2].forEach((p) => {
allPromises.push(p);
});
Promise
.all(allPromises)
.then((results) => {
console.log(results);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment