From 3e8b4dcaa4aa1060238cb1bf263e337a63f85fc7 Mon Sep 17 00:00:00 2001 From: Illia Kovalov Date: Tue, 10 Oct 2023 17:06:21 +0200 Subject: [PATCH 1/2] dont-call-onretry-if-there-is-no-retry: :tada: --- retry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/retry.go b/retry.go index b5d49d5..41a22a5 100644 --- a/retry.go +++ b/retry.go @@ -187,8 +187,6 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) ( break } - config.onRetry(n, err) - for errToCheck, attempts := range attemptsForError { if errors.Is(err, errToCheck) { attempts-- @@ -197,6 +195,8 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) ( } } + config.onRetry(n, err) + // if this is last attempt - don't wait if n == config.attempts-1 { break From 5c696ad829f437a91e96c504b76b5e7fe9fb4bb8 Mon Sep 17 00:00:00 2001 From: Illia Kovalov Date: Tue, 10 Oct 2023 17:10:38 +0200 Subject: [PATCH 2/2] dont-call-onretry-if-there-is-no-retry: oops --- retry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/retry.go b/retry.go index 41a22a5..8f0af05 100644 --- a/retry.go +++ b/retry.go @@ -195,13 +195,13 @@ func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) ( } } - config.onRetry(n, err) - // if this is last attempt - don't wait if n == config.attempts-1 { break } + config.onRetry(n, err) + select { case <-config.timer.After(delay(config, n, err)): case <-config.context.Done():