-
Notifications
You must be signed in to change notification settings - Fork 10
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
update logic of resolve async results #79
Conversation
src/utils.ts
Outdated
@@ -15,18 +15,19 @@ export function asyncResultsAnd(asyncResults: Array<Promise<ValidationResult>>): | |||
return null | |||
} | |||
return new Promise(resolve => { | |||
// 任一不通过,则不通过 | |||
let count = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let count = 0 | |
let validResultCount = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
asyncResults.forEach(asyncResult => asyncResult.then(result => { | ||
// return error if any result is invalid | ||
if (!isValid(result)) { | ||
resolve(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里最好 return 下,invalid 的话就不应该执行后边的逻辑了(虽然在目前的代码下不会导致问题)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/utils.ts
Outdated
if (!isValid(result)) { | ||
resolve(result) | ||
validResultCount = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣 我不是指第 i 个 result invalid 的话,就不去处理后边的 i+1, i+2, ... 的 result,那个处理了也没事的,最多就是多执行两行代码,不会影响逻辑的正确性
我是指,在对第 i 个 result 进行处理的时候,如果它 invalid,就不应该执行后边的:
validResultCount++
// pass if all results are valid
if (validResultCount === asyncResults.length) {
...
}
这会引入一些逻辑上的潜在风险,比如 validResultCount
值不能正确地匹配它的定位,对于它的消费有可能会导致 bug
现在设置 validResultCount
为 -1
以跳过 i+1, i+2, ... 的做法会让逻辑本身变复杂,我个人倾向可以不要这个逻辑?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉了,仅保留 return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥪
No description provided.