Created
October 28, 2023 13:22
-
-
Save StanleyMasinde/e0436448b93978d9e9f9141954c8b586 to your computer and use it in GitHub Desktop.
A simple test on Promise.all()
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
// 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