From bbcd5f820a73ba780a9a277ca15dab1b7e6ae8d6 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Sat, 9 Dec 2023 10:45:07 +0100 Subject: [PATCH] Refactor retry to avoid linter warnings. --- e2e/common/retry.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/e2e/common/retry.go b/e2e/common/retry.go index ea831b98..cf6b430b 100644 --- a/e2e/common/retry.go +++ b/e2e/common/retry.go @@ -8,16 +8,16 @@ func Retry(attempts int, interval time.Duration, fn func() error) error { ticker := time.NewTicker(interval) defer ticker.Stop() var err error - for { //nolint:gosimple//There is no range here. - select { - case <-ticker.C: - attempts-- - err = fn() - if err == nil || attempts == 0 { - return err - } + + for attempts > 0 { + <-ticker.C + attempts-- + err = fn() + if err == nil { + return nil } } + return err } func RetryGet[T any](attempts int, interval time.Duration, fn func() (*T, error)) (*T, error) { @@ -25,14 +25,14 @@ func RetryGet[T any](attempts int, interval time.Duration, fn func() (*T, error) defer ticker.Stop() var err error var obj *T - for { //nolint:gosimple//There is no range here. - select { - case <-ticker.C: - attempts-- - obj, err = fn() - if err == nil || attempts == 0 { - return obj, err - } + + for attempts > 0 { + <-ticker.C + attempts-- + obj, err = fn() + if err == nil { + return obj, nil } } + return obj, err }