Repository navigation
Breaking changes
Backoff is now a function instead of an interface:
type Backoff func(attempt uint64) (next time.Duration, stop bool)Code that only passes the built-in backoffs and middleware to Do compiles without changes. The cases below need edits. The README's Upgrading from v0.6 section has a before and after for each one.
b.Next()is removed. Callb(attempt)instead, whereattemptis the number of retries made so far, starting at 0.BackoffFuncis removed. Write custom backoffs and middleware as afunc(attempt uint64) (time.Duration, bool).- A type with a
Next()method no longer satisfiesBackoff. Add anattempt uint64parameter toNextand pass the method value toDo, for exampleretry.Do(ctx, (&myBackoff{}).Next, f). WithMaxDurationis removed. Usecontext.WithTimeouton the context passed toDo. The returned error wraps bothcontext.DeadlineExceededand the last error fromf. UnlikeWithMaxDuration, the deadline also cancels a call tofthat is still running.Docalls that share one backoff no longer share a retry count. EachDocall counts its retries from 0. Before, aWithMaxRetries(100, b)shared by severalDocalls allowed 100 retries across all of them combined. The migration guide has a middleware that keeps one limit across calls.
Other changes
- One backoff value can be reused across
Docalls and shared between goroutines. - A
Docall that succeeds on the first try allocates nothing, down from 4 allocations when the backoff is built for each call. - Every example has an
// Output:block and runs undergo test.
What's Changed
- Make Backoff a stateless function of the attempt by @sethvargo in #63
Full Changelog: v0.6.0...v0.7.0