diff --git a/retry.go b/retry.go index 5338985..62d6392 100644 --- a/retry.go +++ b/retry.go @@ -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 @@ -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 { @@ -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 {