Documentation
¶
Overview ¶
Package backoff ...
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff struct { // MaxAttempts is the max number of attempts that can occur. MaxAttempts uint // Factor is the factor at which Min will increase after each failed attempt. Factor float64 // Min is the initial backoff time to wait after the first failed attempt. Min time.Duration // Max is the maximum time to wait before retrying. Max time.Duration // NewTimer is used for unit tests. For actual use, this should be set to // time.NewTimer. NewTimer func(time.Duration) *time.Timer // contains filtered or unexported fields }
Backoff represents an exponential backoff.
func New ¶
New returns a new Backoff instance.
Example ¶
package main import ( "context" "time" "github.com/matthewpi/cosmos/internal/backoff" ) func main() { b := backoff.New(3, 2, 1*time.Second, 5*time.Second) for b.Next(context.Background()) { // Do something // break if successful, continue on failure } }
Output:
Click to show internal directories.
Click to hide internal directories.