From 4e3f1776dc94b724a3fc6056d248b05a775f0c90 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 2 Mar 2024 19:09:14 +0800 Subject: [PATCH] chore: coding style (#3957) --- core/fx/retry.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/core/fx/retry.go b/core/fx/retry.go index 1aa002a2..836564c7 100644 --- a/core/fx/retry.go +++ b/core/fx/retry.go @@ -18,7 +18,7 @@ type ( times int interval time.Duration timeout time.Duration - IgnoreErrors []error + ignoreErrors []error } ) @@ -64,7 +64,7 @@ func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opt select { case err := <-errChan: if err != nil { - for _, ignoreErr := range options.IgnoreErrors { + for _, ignoreErr := range options.ignoreErrors { if errors.Is(err, ignoreErr) { return nil } @@ -91,29 +91,31 @@ func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opt return berr.Err() } -// WithRetry customize a DoWithRetry call with given retry times. -func WithRetry(times int) RetryOption { +// WithIgnoreErrors Ignore the specified errors +func WithIgnoreErrors(ignoreErrors []error) RetryOption { return func(options *retryOptions) { - options.times = times + options.ignoreErrors = ignoreErrors } } +// WithInterval customizes a DoWithRetry call with given interval. func WithInterval(interval time.Duration) RetryOption { return func(options *retryOptions) { options.interval = interval } } -func WithTimeout(timeout time.Duration) RetryOption { +// WithRetry customizes a DoWithRetry call with given retry times. +func WithRetry(times int) RetryOption { return func(options *retryOptions) { - options.timeout = timeout + options.times = times } } -// WithIgnoreErrors Ignore the specified errors -func WithIgnoreErrors(IgnoreErrors []error) RetryOption { +// WithTimeout customizes a DoWithRetry call with given timeout. +func WithTimeout(timeout time.Duration) RetryOption { return func(options *retryOptions) { - options.IgnoreErrors = IgnoreErrors + options.timeout = timeout } }