Skip to content

Commit

Permalink
some improvements and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Schindler committed Feb 27, 2015
1 parent f7ce84b commit 0a19c8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package retry

import (
"time"

"github.com/juju/errgo"
)

type RetryOption func(options *retryOptions)
Expand Down Expand Up @@ -45,11 +47,12 @@ func newRetryOptions(options ...RetryOption) retryOptions {
state := retryOptions{
Timeout: DefaultTimeout,
MaxTries: DefaultMaxTries,
Retryer: errgo.Any,
Checker: errgo.Any,
}

for _, option := range options {
option(&state)
}

return state
}
6 changes: 4 additions & 2 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func Do(op func() error, retryOptions ...RetryOption) error {
// Check if we reached the timeout
select {
case <-timeout:
return errgo.Mask(TimeoutError, errgo.Any)
if options.Timeout > 0 {
return errgo.Mask(TimeoutError, errgo.Any)
}
default:
}

Expand All @@ -52,7 +54,7 @@ func Do(op func() error, retryOptions ...RetryOption) error {
if options.Checker != nil && options.Checker(lastError) {
// Check max retries
if tryCounter >= options.MaxTries {
return errgo.WithCausef(lastError, MaxRetriesReachedErr, "Tries %d > %d", tryCounter, options.MaxTries)
return errgo.WithCausef(lastError, MaxRetriesReachedErr, "retry limit reached (%d/%d)", tryCounter, options.MaxTries)
}

if options.Sleep > 0 {
Expand Down

0 comments on commit 0a19c8a

Please sign in to comment.