Created
November 6, 2018 18:03
-
-
Save olehcambel/ea686c5422dd3116a6b4256580937206 to your computer and use it in GitHub Desktop.
Promise.all with catch
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
module.exports = async (items, callback) => { | |
const errors = []; | |
const promises = []; | |
try { | |
if (!items && !Array.isArray(items)) | |
throw `type 'items ${items}' should be Array`; | |
items.forEach(item => { | |
promises.push(callback(item).catch(err => errors.push(err))); | |
}); | |
await Promise.all(promises); | |
if (errors.length) throw errors; | |
} catch (err) { | |
logger.error(err); | |
} | |
}; |
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
await asyncParallel(symbols, async symbol => { | |
const result = await request.get( ... ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment