Skip to content

Instantly share code, notes, and snippets.

@hadnazzar
Last active June 20, 2022 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadnazzar/9ed8ad866285ee44766f82bbfcd816a3 to your computer and use it in GitHub Desktop.
Save hadnazzar/9ed8ad866285ee44766f82bbfcd816a3 to your computer and use it in GitHub Desktop.
const promiseWithMilliseconds = (ms, index) => {
return new Promise((resolve,reject) => {
console.time(`Time:${index}`)
setTimeout(() => {
console.timeEnd(`Time:${index}`)
return resolve(`Resolved in ${ms}`)
}, ms);
})
}
Promise.all([promiseWithMilliseconds(3000,1), promiseWithMilliseconds(2000,2), promiseWithMilliseconds(1000,3)])
.then((result) => {
console.log('Result', result)
})
.catch((error) => console.log(`Error: ${error}`))
/*
Time:3: 1002.9638671875 ms
Time:3: 1.006s
Time:2: 2002.5029296875 ms
Time:2: 2.003s
Time:1: 3001.677001953125 ms
Time:1: 3.002s
Result (3) ['Resolved in 3000', 'Resolved in 2000', 'Resolved in 1000']
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment