Skip to content

Commit 3e84ba3

Browse files
committed
replace Promise.all by Promise.allSettled
1 parent 6b58e73 commit 3e84ba3

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/utils/DataUtils.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
export const mergeMultipleDataSources = async (promises, maxCount) => {
2-
let values = await Promise.all(promises)
3-
values = values.filter((value) => value && value.length > 0)
4-
const nbrTags = values.length
5-
let minLength = Math.min(maxCount, ...values.map((v) => v.length))
2+
let promisesRequests = await Promise.allSettled(promises)
3+
let promisesValues = promisesRequests
4+
.map((res) => {
5+
let value = res.value
6+
if (res.status === 'rejected') {
7+
value = []
8+
}
9+
return value
10+
})
11+
.filter(Boolean)
12+
.filter((value) => value.length > 1)
13+
const nbrTags = promisesValues.length
14+
let minLength = Math.min(maxCount, ...promisesValues.map((v) => v.length))
615
const data = []
716
for (let index = 0; index < minLength; index++) {
817
for (let i = 0; i < nbrTags; i++) {
9-
data.push(values[i][index])
18+
data.push(promisesValues[i][index])
1019
}
1120
}
1221
return data

0 commit comments

Comments
 (0)