Skip to content

Instantly share code, notes, and snippets.

@altherlex
Last active August 6, 2019 04:29
Show Gist options
  • Save altherlex/641f5b4fcd618aa2b2dfe279d31803ac to your computer and use it in GitHub Desktop.
Save altherlex/641f5b4fcd618aa2b2dfe279d31803ac to your computer and use it in GitHub Desktop.
node js series VS parallel
// in Series
const result = await rows.reduce((p, album, i) => p.then(async () => {
var hotlink_url = '';
try {
hotlink_url = await Helper.getHotlink(album.post_url, browser);
const r = await pool.query(state, [ album.id, null, moment(new Date()) ]);
return r.rows[0];
} catch(e){
console.log('erro ocorrido:', e);
}
}), Promise.resolve()); // reduce end
// --------------------------------------------------------
// in Parallel
const result = await rows.map(async album => {
var hotlink_url = '';
try {
hotlink_url = await Helper.getHotlink(album.post_url, browser);
const r = await pool.query(state, [album.id, null, moment(new Date())]);
return r.rows[0];
} catch (e) {
console.log('erro ocorrido:', e);
}
}); // map end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment