chore: coding style (#3957)

master^2
Kevin Wan 9 months ago committed by GitHub
parent e38036cea2
commit 4e3f1776dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,7 +18,7 @@ type (
times int times int
interval time.Duration interval time.Duration
timeout 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 { select {
case err := <-errChan: case err := <-errChan:
if err != nil { if err != nil {
for _, ignoreErr := range options.IgnoreErrors { for _, ignoreErr := range options.ignoreErrors {
if errors.Is(err, ignoreErr) { if errors.Is(err, ignoreErr) {
return nil return nil
} }
@ -91,29 +91,31 @@ func retry(ctx context.Context, fn func(errChan chan error, retryCount int), opt
return berr.Err() return berr.Err()
} }
// WithRetry customize a DoWithRetry call with given retry times. // WithIgnoreErrors Ignore the specified errors
func WithRetry(times int) RetryOption { func WithIgnoreErrors(ignoreErrors []error) RetryOption {
return func(options *retryOptions) { return func(options *retryOptions) {
options.times = times options.ignoreErrors = ignoreErrors
} }
} }
// WithInterval customizes a DoWithRetry call with given interval.
func WithInterval(interval time.Duration) RetryOption { func WithInterval(interval time.Duration) RetryOption {
return func(options *retryOptions) { return func(options *retryOptions) {
options.interval = interval 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) { return func(options *retryOptions) {
options.timeout = timeout options.times = times
} }
} }
// WithIgnoreErrors Ignore the specified errors // WithTimeout customizes a DoWithRetry call with given timeout.
func WithIgnoreErrors(IgnoreErrors []error) RetryOption { func WithTimeout(timeout time.Duration) RetryOption {
return func(options *retryOptions) { return func(options *retryOptions) {
options.IgnoreErrors = IgnoreErrors options.timeout = timeout
} }
} }

Loading…
Cancel
Save