retry

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-01 22:07:18 * @FilePath: \go-toolbox\pkg\retry\retry.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoRetry

func DoRetry(attemptCount int, interval time.Duration, f DoFun, errCallFun ErrCallbackFunc, funcName ...string) (err error)

DoRetry 定义了重试操作,执行指定次数的尝试

Types

type DoFun

type DoFun func() error

DoFun 定义执行函数的类型

type ErrCallbackFunc

type ErrCallbackFunc func(nowAttemptCount, remainCount int, err error, funcName ...string)

ErrCallbackFunc 是重试时的错误回调函数类型 nowAttemptCount 表示当前尝试次数 remainCount 表示剩余尝试次数 err 是当前执行时的错误信息

type Retry

type Retry struct {
	// contains filtered or unexported fields
}

Retry 结构体用于实现重试机制

func NewRetry

func NewRetry() *Retry

NewRetry 创建一个重试器,返回一个 Retry 实例

func (*Retry) Do

func (m *Retry) Do(f DoFun) (err error)

Do 为 Retry 结构体定义执行函数,执行指定函数 f

func (*Retry) SetAttemptCount

func (r *Retry) SetAttemptCount(attemptCount int) *Retry

SetAttemptCount 设置最大尝试次数,返回 Retry 实例以支持链式调用

func (*Retry) SetErrCallback

func (r *Retry) SetErrCallback(errCallbackFunc ErrCallbackFunc) *Retry

SetErrCallback 设置错误回调函数,返回 Retry 实例以支持链式调用

func (*Retry) SetInterval

func (r *Retry) SetInterval(interval time.Duration) *Retry

SetInterval 设置重试间隔时间,返回 Retry 实例以支持链式调用

Jump to

Keyboard shortcuts

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