avast/retry-go

The number of passed in OnRetry is inconsistent

FarmerChillax opened this issue · 0 comments

I also found a problem. When attempts is equal to 0, the number of times passed in onRetry is inconsistent with when attempts is not equal to 0.
Here is a minimal example:

  • when set Attempts != 0
func main() {
	retry.Do(
		func() error {
			return errors.New("some error")
		},
		retry.Attempts(3),
		retry.OnRetry(func(n uint, err error) {
			fmt.Println("retry OnRetry:", n, err)
		}),
	)
}

outputs:

retry OnRetry: 0 some error
retry OnRetry: 1 some error
retry OnRetry: 2 some error
  • when set Attempts = 0
func main() {
	retry.Do(
		func() error {
			return errors.New("some error")
		},
		retry.Attempts(0),
		retry.OnRetry(func(n uint, err error) {
			fmt.Println("retry OnRetry:", n, err)
		}),
	)
}
retry OnRetry: 1 some error
retry OnRetry: 2 some error
retry OnRetry: 3 some error
retry OnRetry: 4 some error
retry OnRetry: 5 some error
^Csignal: interrupt