Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Retry ¶
func Retry( ctx context.Context, strategy Strategy, fn func(ctx context.Context) (shouldRetry bool, err error), ) error
Retry retries the given function with the given Strategy, until function returns no error, strategy returns stop=true, function returns error and retry=false, or ctx deadline is exceeded.
Types ¶
type Strategy ¶
Strategy represents a retry strategy. See Retry for more details.
var DefaultStrategy Strategy = CombinedStrategy( LimitStrategy(10), ExponentialStrategy(1*time.Millisecond, 1024*time.Millisecond))
DefaultStrategy returns an exponential backoff strategy with a limit of 10, a min sleep time of 1ms and a max sleep time of 1024ms. At most, this strategy yields a retry mechanism that can last approximately 2 seconds.
func CombinedStrategy ¶
CombinedStrategy returns a retry strategy that combines all the given strategies using the following rules:
- If any returns stop=true, then stop=true is returned.
- If multiple return a sleep time that is non-zero, then the biggest sleep value is used.
func ExponentialStrategy ¶
ExponentialStrategy returns a retry strategy that never stops but increments the sleep time from min to max in power of 2 increments. A min of zero or less never sleeps.
func LimitStrategy ¶
LimitStrategy returns a retry strategy that stops after limit number of retries has been reached.
func SequentialStrategy ¶
SequentialStrategy returns a retry strategy that never stops and retries always after 'every' duration.