Ai
1 Star 0 Fork 0

ks3sdk/aws-sdk-go
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
try.go 788 Bytes
一键复制 编辑 原始数据 按行查看 历史
爱薄荷的小虾米 提交于 2020-12-21 14:09 +08:00 . 【优化】
package s3
import "errors"
// MaxRetries is the maximum number of retries before bailing.
var MaxRetries = 10
var errMaxRetriesReached = errors.New("exceeded retry limit")
// Func represents functions that can be retried.
type Func func(attempt int) (retry bool, err error)
// Do keeps trying the function until the second argument
// returns false, or no error is returned.
func Do(fn Func) error {
var err error
var cont bool
attempt := 1
for {
cont, err = fn(attempt)
if !cont || err == nil {
break
}
attempt++
if attempt > MaxRetries {
return errMaxRetriesReached
}
}
return err
}
// IsMaxRetries checks whether the error is due to hitting the
// maximum number of retries or not.
func IsMaxRetries(err error) bool {
return err == errMaxRetriesReached
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ks3sdk/aws-sdk-go.git
git@gitee.com:ks3sdk/aws-sdk-go.git
ks3sdk
aws-sdk-go
aws-sdk-go
v1.0.7

搜索帮助