Skip to content

Instantly share code, notes, and snippets.

@olehcambel
Created November 6, 2018 18:03
Show Gist options
  • Save olehcambel/ea686c5422dd3116a6b4256580937206 to your computer and use it in GitHub Desktop.
Save olehcambel/ea686c5422dd3116a6b4256580937206 to your computer and use it in GitHub Desktop.
Promise.all with catch
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);
}
};
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