Skip to content

Instantly share code, notes, and snippets.

@StanleyMasinde
Created October 28, 2023 13:22
Show Gist options
  • Save StanleyMasinde/e0436448b93978d9e9f9141954c8b586 to your computer and use it in GitHub Desktop.
Save StanleyMasinde/e0436448b93978d9e9f9141954c8b586 to your computer and use it in GitHub Desktop.
A simple test on Promise.all()
// Promises without dates
(async function main() {
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Promise 1')
}, 5000)
})
const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Promise two')
}, 100)
})
const allPromises = await Promise.all([promise1, promise2])
console.log(allPromises)
})()
// Promises with dates
(async function main() {
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Promise 1', new Date())
resolve('Promise 1')
}, 5000)
})
const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Promise 2', new Date())
resolve('Promise two')
}, 100)
})
const allPromises = await Promise.all([promise1, promise2])
console.log(allPromises)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment