Last active
December 16, 2017 02:01
-
-
Save sunkibaek/9d73efc9f71ed52bd1e422c33f28a9fb to your computer and use it in GitHub Desktop.
Promise all with timeout
This file contains hidden or 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 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