Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
attemptsForError[err] = attempts
}

shouldRetry := true
for shouldRetry {
shouldRetry:
for {
t, err := retryableFunc()
if err == nil {
return t, nil
Expand All @@ -194,13 +194,15 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (
if errors.Is(err, errToCheck) {
attempts--
attemptsForError[errToCheck] = attempts
shouldRetry = shouldRetry && attempts > 0
if attempts <= 0 {
break shouldRetry
}
}
}

// if this is last attempt - don't wait
if n == config.attempts-1 {
break
break shouldRetry
}
n++
select {
Expand All @@ -212,8 +214,6 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (

return emptyT, append(errorLog, context.Cause(config.context))
}

shouldRetry = shouldRetry && n < config.attempts
}

if config.lastErrorOnly {
Expand Down