Skip to content

Commit

Permalink
Added Cutomizable stop to Retry Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish Bhat committed Jun 29, 2019
1 parent 6bcf328 commit b0e780d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func Do(attempts int, sleep time.Duration, fn func() error) error {
if err := fn(); err != nil {
if s, ok := err.(Stop); ok {
// Return the original error for later checking
return s.error
return s.OriginalError
}

if attempts--; attempts > 0 {
Expand All @@ -24,5 +24,9 @@ func Do(attempts int, sleep time.Duration, fn func() error) error {
// Stop is used to return error and stop retrying
// Return Stop{err}, if you want to stop despite Error
type Stop struct {
error
OriginalError error
}

func (stop Stop) Error() string {
return stop.OriginalError.Error()
}

0 comments on commit b0e780d

Please sign in to comment.