|
@@ -487,18 +487,33 @@ function _emitSocketProgress (uploader, progressData, file) {
|
|
|
|
|
|
const emitSocketProgress = throttle(_emitSocketProgress, 300, {leading: true, trailing: true})
|
|
|
|
|
|
-function rejectIfAllRejected (promiseArray) {
|
|
|
+function settle (promises) {
|
|
|
+ const resolutions = []
|
|
|
const rejections = []
|
|
|
- promiseArray.forEach((result) => {
|
|
|
- if (!result.isFulfilled()) {
|
|
|
- rejections.push(result.reason())
|
|
|
+ function resolved (value) {
|
|
|
+ resolutions.push(value)
|
|
|
+ }
|
|
|
+ function rejected (error) {
|
|
|
+ rejections.push(error)
|
|
|
+ }
|
|
|
+
|
|
|
+ const wait = Promise.all(
|
|
|
+ promises.map((promise) => promise.then(resolved, rejected))
|
|
|
+ )
|
|
|
+
|
|
|
+ return wait.then(() => {
|
|
|
+ if (rejections.length === promises.length) {
|
|
|
+ // Very ad-hoc multiple-error reporting, should wrap this in a
|
|
|
+ // CombinedError or whatever kind of error class instead.
|
|
|
+ const error = rejections[0]
|
|
|
+ error.errors = rejections
|
|
|
+ return Promise.reject(error)
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ successful: resolutions,
|
|
|
+ failed: rejections
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
- if (rejections.length > 0) {
|
|
|
- return Promise.reject(rejections[0])
|
|
|
- }
|
|
|
- return promiseArray
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
@@ -527,5 +542,5 @@ module.exports = {
|
|
|
findAllDOMElements,
|
|
|
getSocketHost,
|
|
|
emitSocketProgress,
|
|
|
- rejectIfAllRejected
|
|
|
+ settle
|
|
|
}
|