Skip to content

Commit

Permalink
Make sure DelayType function gets consistent values of n
Browse files Browse the repository at this point in the history
Without this change DelayType function gets n either from
0,1,2,... or from 1,2,3,... depending on the value of Attempts
config value.

This change unifies the behaviour and makes n always take values from
1,2,3,...

Fixes #124

Signed-off-by: Piotr Jastrzebski <[email protected]>
  • Loading branch information
haaawk committed Jan 21, 2025
1 parent 01d7e00 commit be23843
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
if n == config.attempts-1 {
break
}

n++
select {
case <-config.timer.After(delay(config, n, err)):
case <-config.context.Done():
Expand All @@ -213,7 +213,6 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
return emptyT, append(errorLog, config.context.Err())
}

n++
shouldRetry = shouldRetry && n < config.attempts
}

Expand Down

0 comments on commit be23843

Please sign in to comment.