Created
March 15, 2021 18:46
-
-
Save meetkabeershah/5fd9b0f75f88b6f3d5baabffc2eba973 to your computer and use it in GitHub Desktop.
buyer-assist-assignment.js
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 myPromise1 = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve('myPromise1'); | |
}, 300); | |
}); | |
const myPromise2 = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve('myPromise2'); | |
}, 300); | |
}); | |
const myPromise3 = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve('myPromise3'); | |
}, 300); | |
}); | |
const series = async (promises, callback) => { | |
try{ | |
for (const p of promises) { | |
const value = await p; | |
callback(null, value); | |
} | |
} | |
catch(ex){ | |
callback(ex, null); | |
} | |
} | |
series([myPromise1, myPromise2, myPromise3], (err, value)=>{ | |
if(err) { | |
throw err | |
} | |
console.log('value: ', value) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment