Guest User

Untitled

a guest
Aug 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. const safePromiseAll = promises =>
  2. Promise.all(promises.map(p => p.then(
  3. value => ({ value }),
  4. error => ({ error })
  5. )))
  6. .then(all =>
  7. all.reduce((acc, { value, error }) => {
  8. if (error) {
  9. acc.errors.push(error);
  10. } else {
  11. acc.values.push(value);
  12. }
  13.  
  14. return acc;
  15. }, { errors: [], values: [] })
  16. );
Add Comment
Please, Sign In to add comment