mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +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
|
var i uint
|
||||||
for i < config.retryTimes {
|
for i < config.retryTimes {
|
||||||
err := retryFunc()
|
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 {
|
select {
|
||||||
case <-time.After(config.backoffStrategy.CalculateInterval()):
|
case <-time.After(config.backoffStrategy.CalculateInterval()):
|
||||||
case <-config.context.Done():
|
case <-config.context.Done():
|
||||||
return errors.New("retry is cancelled")
|
return errors.New("retry is cancelled")
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user