Last active
June 20, 2022 22:42
-
-
Save hadnazzar/9ed8ad866285ee44766f82bbfcd816a3 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 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