@@ -45,14 +45,13 @@ func main() {
4545 }
4646
4747 ctx := context.Background ()
48- err := retry.Fibonacci (ctx, 1 *time.Second , func (ctx context.Context ) error {
48+ if err := retry.Fibonacci (ctx, 1 *time.Second , func (ctx context.Context ) error {
4949 if err := db.PingContext (ctx); err != nil {
5050 // This marks the error as retryable
5151 return retry.RetryableError (err)
5252 }
5353 return nil
54- })
55- if err != nil {
54+ }); err != nil {
5655 log.Fatal (err)
5756 }
5857}
@@ -121,10 +120,7 @@ To reduce the changes of a thundering herd, add random jitter to the returned
121120value.
122121
123122``` golang
124- b , err := NewFibonacci (1 * time.Second )
125- if err != nil {
126- // handle err
127- }
123+ b := NewFibonacci (1 * time.Second )
128124
129125// Return the next value, +/- 500ms
130126b = WithJitter (500 *time.Millisecond , b)
@@ -139,10 +135,7 @@ To terminate a retry, specify the maximum number of _retries_. Note this
139135is _ retries_ , not _ attempts_ . Attempts is retries + 1.
140136
141137``` golang
142- b , err := NewFibonacci (1 * time.Second )
143- if err != nil {
144- // handle err
145- }
138+ b := NewFibonacci (1 * time.Second )
146139
147140// Stop after 4 retries, when the 5th attempt has failed. In this example, the worst case elapsed
148141// time would be 1s + 1s + 2s + 3s = 7s.
@@ -154,10 +147,7 @@ b = WithMaxRetries(4, b)
154147To ensure an individual calculated duration never exceeds a value, use a cap:
155148
156149``` golang
157- b , err := NewFibonacci (1 * time.Second )
158- if err != nil {
159- // handle err
160- }
150+ b := NewFibonacci (1 * time.Second )
161151
162152// Ensure the maximum value is 2s. In this example, the sleep values would be
163153// 1s, 1s, 2s, 2s, 2s, 2s...
@@ -169,10 +159,7 @@ b = WithCappedDuration(2 * time.Second, b)
169159For a best-effort limit on the total execution time, specify a max duration:
170160
171161``` golang
172- b , err := NewFibonacci (1 * time.Second )
173- if err != nil {
174- // handle err
175- }
162+ b := NewFibonacci (1 * time.Second )
176163
177164// Ensure the maximum total retry time is 5s.
178165b = WithMaxDuration (5 * time.Second , b)
0 commit comments