Skip to content

Commit

Permalink
expose IsRetryable func as a type
Browse files Browse the repository at this point in the history
  • Loading branch information
ben1009 authored and ti-chi-bot committed Jun 25, 2021
1 parent a5354c8 commit eafb5c2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/retry/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ const (
// Option ...
type Option func(*retryOptions)

// IsRetryable checks the error is safe or worth to retry, eg. "context.Canceled" better not retry
type IsRetryable func(error) bool

type retryOptions struct {
maxTries int64
backoffBaseInMs float64
backoffCapInMs float64
// isRetryable checks the error is safe to retry or not, eg. "context.Canceled" better not retry
isRetryable func(error) bool
isRetryable IsRetryable
}

func newRetryOptions() *retryOptions {
Expand Down Expand Up @@ -80,7 +82,7 @@ func WithInfiniteTries() Option {
}

// WithIsRetryableErr configures the error should retry or not, if not set, retry by default
func WithIsRetryableErr(f func(error) bool) Option {
func WithIsRetryableErr(f IsRetryable) Option {
return func(o *retryOptions) {
if f != nil {
o.isRetryable = f
Expand Down

0 comments on commit eafb5c2

Please sign in to comment.