Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultMaxAttempts is the default number of total attempts for network operations. DefaultMaxAttempts = 3 // DefaultInitialDelay is the initial delay before the first retry. DefaultInitialDelay = 2 * time.Second // DefaultMaxDelay is the maximum delay between retry attempts. DefaultMaxDelay = 30 * time.Second // DefaultBackoffMultiplier is the multiplier applied to the delay on each subsequent retry. DefaultBackoffMultiplier = 2.0 )
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do executes the given operation, retrying on error according to cfg. It uses exponential backoff with random jitter between attempts and respects context cancellation during waits.
If cfg is zero-valued, DefaultConfig is used.
Types ¶
type Config ¶
type Config struct {
// MaxAttempts is the total number of attempts (including the initial one).
// Values <= 0 are treated as 1 (no retries).
MaxAttempts int
// InitialDelay is the base delay before the first retry.
InitialDelay time.Duration
// MaxDelay caps the delay between any two consecutive attempts.
MaxDelay time.Duration
// BackoffMultiplier scales the delay on each successive retry.
BackoffMultiplier float64
}
Config controls the behavior of Do. A zero-value Config will be treated as DefaultConfig.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults for network operations.
Click to show internal directories.
Click to hide internal directories.