Skip to content

v0.7.0

Latest

Choose a tag to compare

@sethvargo sethvargo released this 23 Nov 21:11
Immutable release. Only release title and notes can be modified.
b471b87

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. Call b(attempt) instead, where attempt is the number of retries made so far, starting at 0.
  • BackoffFunc is removed. Write custom backoffs and middleware as a func(attempt uint64) (time.Duration, bool).
  • A type with a Next() method no longer satisfies Backoff. Add an attempt uint64 parameter to Next and pass the method value to Do, for example retry.Do(ctx, (&myBackoff{}).Next, f).
  • WithMaxDuration is removed. Use context.WithTimeout on the context passed to Do. The returned error wraps both context.DeadlineExceeded and the last error from f. Unlike WithMaxDuration, the deadline also cancels a call to f that is still running.
  • Do calls that share one backoff no longer share a retry count. Each Do call counts its retries from 0. Before, a WithMaxRetries(100, b) shared by several Do calls 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 Do calls and shared between goroutines.
  • A Do call 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 under go test.

What's Changed

  • Make Backoff a stateless function of the attempt by @sethvargo in #63

Full Changelog: v0.6.0...v0.7.0