Skip to content

Instantly share code, notes, and snippets.

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/98fb1e1a7984c7eb0fb90978a1393859 to your computer and use it in GitHub Desktop.
Save hadnazzar/98fb1e1a7984c7eb0fb90978a1393859 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);
})
}
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