retryx

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 2 Imported by: 0

README

retryx 包 Package

retryx 提供最大尝试次数、基础延迟、最大延迟和可选 jitter 计算。

Use ShouldRetry with errors that expose errx.Error retryability or context cancellation semantics.

Documentation

Overview

Package retryx 提供 SDK 无关的重试策略、退避和可重试判断。

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldRetry

func ShouldRetry(err error) bool

ShouldRetry reports whether err is a kernel error marked retryable.

Types

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
}

func DefaultRetryPolicy

func DefaultRetryPolicy() RetryPolicy

func (RetryPolicy) Delay

func (p RetryPolicy) Delay(attempt int) time.Duration
Example
package main

import (
	"time"

	"github.com/ZoneCNH/kernel/retryx"
)

func main() {
	policy := retryx.RetryPolicy{MaxAttempts: 3, BaseDelay: 10 * time.Millisecond, MaxDelay: time.Second}
	_ = policy.Delay(2)
}

func (RetryPolicy) DelayWithJitter

func (p RetryPolicy) DelayWithJitter(attempt int, ratio float64, fraction float64) time.Duration

func (RetryPolicy) Validate

func (p RetryPolicy) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL