Skip to content

Instantly share code, notes, and snippets.

@xameeramir
Created March 15, 2021 18:46
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 xameeramir/5fd9b0f75f88b6f3d5baabffc2eba973 to your computer and use it in GitHub Desktop.
Save xameeramir/5fd9b0f75f88b6f3d5baabffc2eba973 to your computer and use it in GitHub Desktop.
buyer-assist-assignment.js
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