Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
修复重新发送计时器错误
错误描述
在 Re-delivery frame 时,对 frame 的 timestamp 进行了重新赋值,但程序运行需要消耗时间,导致会出现几毫秒的误差,于是在定时器下一次被触发时,nowTimestamp - frame.timestamp 比 (retryTimeInterval/1000.0) 小几毫秒,导致多数情况下定时器每执行两次才会触发一次 Re-delivery frame 逻辑,误差测试如下:
修复方案
为 Frame 增加一个重试次数(retryCount)变量,在 redeliver 方法中,比较 时间差值(nowTimestamp - frame.timestamp) 与 重试时间*重试次数((retryTimeInterval/1000.0) * frame.retryCount)的大小,即:
说明
以上是我能想到的处理方案,如果有更好的处理方式,欢迎回复我。