Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The number of passed in OnRetry is inconsistent #113

Closed
FarmerChillax opened this issue Mar 6, 2024 · 0 comments
Closed

The number of passed in OnRetry is inconsistent #113

FarmerChillax opened this issue Mar 6, 2024 · 0 comments

Comments

@FarmerChillax
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants