retry.Do extra functionality

Hello fellow gophers,

I want to use retry.Do, but would like it to offer me more features. For example, the errors of each retry can only be retrieved together, as a slice, after either a Do has succeeded or it failed the max amount of times.

Secondly, the config paramters (MaxJitter, DelayType, MaxRetries) are configured when you call Do, then they remain static. I would like a functionality to be able to start a retry.Do call, then based on its state, to modify these parameters real time.

Is there another package that offers this extra, fine-grained functionality ? How about your usage of retry.Do, do you have anything extra that you would like it to offer ?

Can you specify what package is this?

I’m guessing this is the package.

1 Like

After reading the source code (and assuming we’re talking about the same package), I suppose you could implement your own DelayTypeFunc that delegates to some other delay function:

type ChangeableDelayType struct {
    Func retry.DelayTypeFunc
}

func (c *ChangeableDelayType) DelayType(n uint, err error, config *Config) time.Duration {
    return c.Func(n, err, config)
}

// ...

c := &ChangeableDelayType{
    Func: retry.BackOfDelay,
}

retry.Do(
    /* ... */,
    retry.DelayType(c.DelayType),
)

// Now you can change c.Func to change the behavior, but be careful
// with concurrent access to c.Func:  Maybe add a mutex to
// synchronize access.
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.