Last active
April 8, 2022 14:45
-
-
Save hongphuc5497/2ab17fbf80874fd0b9da099200c086b0 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 SamplePromise = (index) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(`Promise ${index}`); | |
}, 1000); | |
}); | |
}; | |
const withoutPromiseAll = () => { | |
console.time('Without Promise.all'); | |
[...Array(10).keys()].map(async (index) => { | |
await SamplePromise(index); | |
}); | |
console.timeEnd('Without Promise.all'); | |
}; | |
withoutPromiseAll(); | |
const withPromiseAll = () => { | |
console.time('With Promise.all'); | |
Promise.all([...Array(10).keys()].map(async (index) => { | |
await SamplePromise(index); | |
})); | |
console.timeEnd('With Promise.all'); | |
}; | |
withPromiseAll(); | |
const withPromiseAllSettled = () => { | |
console.time('With Promise.allSettled'); | |
Promise.allSettled([...Array(10).keys()].map(async (index) => { | |
await SamplePromise(index); | |
})); | |
console.timeEnd('With Promise.allSettled'); | |
}; | |
withPromiseAllSettled(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment