Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for conditional errors #19

Closed
doodles526 opened this issue Aug 21, 2015 · 1 comment
Closed

Allow for conditional errors #19

doodles526 opened this issue Aug 21, 2015 · 1 comment

Comments

@doodles526
Copy link

Add a set of functions such as

func ConditionalRetry(o Operation, c Conditional, b Backoff) error
func ConditionalRetryNotify(o Operation, c Conditional, n Notify, b Backoff) error

where

func Conditional(e error) bool

The idea being that some operations return errors, and you only want to backoff on certain errors. Otherwise you just want to drop the error through to the receiver of ConditionalRetry or ConditionalRetryNotify

I already implemented a hacky version of this for a project that I needed to have that functionality. If there's interest of supporting this I could clean up what I have and throw up a PR

@cenkalti
Copy link
Owner

Why not simply wrap the operation function?

Example:

operation := func() error {
    err := realOperation()
    if err == ErrNotThatBad {
        return nil
    }
    return err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants