mirror of
https://github.com/duke-git/lancet.git
synced 2025-09-26 19:41:20 +08:00
perf(retry): remove the waiting time after the last retry (#309)
This commit is contained in:
@@ -130,14 +130,16 @@ func Retry(retryFunc RetryFunc, opts ...Option) error {
|
||||
var i uint
|
||||
for i < config.retryTimes {
|
||||
err := retryFunc()
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if i < config.retryTimes-1 { // Only wait if it's not the last retry
|
||||
select {
|
||||
case <-time.After(config.backoffStrategy.CalculateInterval()):
|
||||
case <-config.context.Done():
|
||||
return errors.New("retry is cancelled")
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
Reference in New Issue
Block a user