Skip to content

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

@yokuze

Description

@yokuze

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).

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions