Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const safePromiseAll = promises =>
- Promise.all(promises.map(p => p.then(
- value => ({ value }),
- error => ({ error })
- )))
- .then(all =>
- all.reduce((acc, { value, error }) => {
- if (error) {
- acc.errors.push(error);
- } else {
- acc.values.push(value);
- }
- return acc;
- }, { errors: [], values: [] })
- );
Add Comment
Please, Sign In to add comment