Last active
August 6, 2019 04:29
-
-
Save altherlex/641f5b4fcd618aa2b2dfe279d31803ac to your computer and use it in GitHub Desktop.
node js series VS parallel
This file contains hidden or 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
// 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