Skip to content

Commit 370267b

Browse files
Zenas-He何智超
andauthored
Update logic of async results resolving (#79)
* update logic of resolve async results * update text * fix review * fix review Co-authored-by: 何智超 <[email protected]>
1 parent 77c4327 commit 370267b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ export function asyncResultsAnd(asyncResults: Array<Promise<ValidationResult>>):
1515
return null
1616
}
1717
return new Promise(resolve => {
18-
// 任一不通过,则不通过
18+
let validResultCount = 0
1919
asyncResults.forEach(asyncResult => asyncResult.then(result => {
20+
// return error if any result is invalid
2021
if (!isValid(result)) {
2122
resolve(result)
23+
return
2224
}
23-
}))
24-
// 所有都通过,则通过
25-
return Promise.all(asyncResults).then(results => {
26-
if (results.every(isValid)) {
25+
26+
validResultCount++
27+
// pass if all results are valid
28+
if (validResultCount === asyncResults.length) {
2729
resolve(null)
2830
}
29-
})
31+
}))
3032
})
3133
}
3234

0 commit comments

Comments
 (0)