Skip to content

Commit

Permalink
Merge pull request #27 from lebauce/default-config
Browse files Browse the repository at this point in the history
Export default configuration
  • Loading branch information
JaSei authored Feb 25, 2020
2 parents 88a508d + 5ea276b commit adee513
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,28 @@ import (
// Function signature of retryable function
type RetryableFunc func() error

var (
DefaultAttempts = uint(10)
DefaultDelay = 100 * time.Millisecond
DefaultMaxJitter = 100 * time.Millisecond
DefaultOnRetry = func(n uint, err error) {}
DefaultRetryIf = IsRecoverable
DefaultDelayType = CombineDelay(BackOffDelay, RandomDelay)
DefaultLastErrorOnly = false
)

func Do(retryableFunc RetryableFunc, opts ...Option) error {
var n uint

//default
config := &Config{
attempts: 10,
delay: 100 * time.Millisecond,
maxJitter: 100 * time.Millisecond,
onRetry: func(n uint, err error) {},
retryIf: IsRecoverable,
delayType: CombineDelay(BackOffDelay, RandomDelay),
lastErrorOnly: false,
attempts: DefaultAttempts,
delay: DefaultDelay,
maxJitter: DefaultMaxJitter,
onRetry: DefaultOnRetry,
retryIf: DefaultRetryIf,
delayType: DefaultDelayType,
lastErrorOnly: DefaultLastErrorOnly,
}

//apply opts
Expand Down

0 comments on commit adee513

Please sign in to comment.