Created
June 20, 2022 23:57
-
-
Save hadnazzar/98fb1e1a7984c7eb0fb90978a1393859 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); | |
}) | |
} | |
const promiseWithMillisecondsToFail = (ms,index) => { | |
return new Promise((resolve,reject) => { | |
setTimeout(() => { | |
return reject(`Failed promise after: ${ms} ms`) | |
}, ms); | |
}) | |
} | |
Promise.all([promiseWithMillisecondsToFail(1000,1), promiseWithMilliseconds(2000,2), promiseWithMilliseconds(3000,3)]) | |
.then((result) => { | |
console.log('Result', result) | |
}) | |
.catch((error) => console.log(`Catch block, Error: ${error}`)) | |
/* | |
Catch block, Error: Failed promise after: 1000 ms | |
Time:2: 2002.31396484375 ms | |
Time:2: 2.003s | |
Time:3: 3001.794921875 ms | |
Time:3: 3.002s | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment