Skip to content

The number of passed in OnRetry is inconsistent #113

@FarmerChillax

Description

@FarmerChillax

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions