An implementation of capped exponential backoff algorithm with jitter.
// ...
// define condition
cond := func() bool {
// try to establish connection to an external resource
if err := TryConnect(); err != nil {
return false
}
return true
}
// create a new retrier
retrier, err := retry.New(retry.DefaultConfiguration(), retry.DefaultRandomFunc)
if err != nil {
panic(err)
}
// start retrying
notify := retrier.Retry(context.Background(), cond, true)
// wait for notification
<-notify
// ...