Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding Promise utility that lets all Promises resolve/reject, but rejects if any are rejected #10

Open
yokuze opened this issue Jan 7, 2020 · 0 comments
Assignees

Comments

@yokuze
Copy link
Contributor

yokuze commented Jan 7, 2020

We would like a Promise utility that acts a little like allSettled in that it allows all Promises in a given array of Promises to resolve or reject, but the end result is a rejected Promise if any Promise in the array is rejected.

This simplest implementation of this would be:

return Promise.allSettled(contentDocPromises).then((results) => {
   for (let result of results) {
      if (result.status !== 'fulfilled') {
         return Promise.reject(result.reason);
      }
   }
});

But that implementation loses the values that resolved Promises returned and only surfaces a single reason for rejection when there could be multiple.

Perhaps the function could resolve with the array of resolved values if all Promises resolve, and reject with an array of rejection reasons for any rejected Promises (or just reject with the array of results so that resolved values are not lost).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants