loop

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package loop 提供了一个循环执行某个方法的功能,可以自定义执行时间等。 用法: l := loop.New() l.Do(方法)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loop

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

Loop 定义循环执行任务的对象.

func New

func New(options ...Option) *Loop

New 创建一个新的 Loop 实例.

func (*Loop) CalculateInterval

func (l *Loop) CalculateInterval(loopedTimes uint64) time.Duration

CalculateInterval 传入当前循环次数,计算间隔时间

func (*Loop) Do

func (l *Loop) Do(f func() (bool, error)) error

Do 循环的执行一个方法 这个被循环执行的方法有两个返回值,第一个返回值控制是否需要退出循环,第二为任务执行的错误信息.

type Option

type Option func(*Loop)

Option 定义 Loop 对象的参数配置选项.

func WithContext added in v1.3.0

func WithContext(ctx context.Context) Option

WithContext set the context to cancel loop

func WithDeclineLimit

func WithDeclineLimit(t time.Duration) Option

WithDeclineLimit 设置衰退延迟的最大值,默认不限制最大值.

func WithDeclineRatio

func WithDeclineRatio(n float64) Option

WithDeclineRatio 设置衰退延迟的比例,默认是 1.

func WithInterval

func WithInterval(t time.Duration) Option

WithInterval 设置每次循环的间隔时间.

func WithMaxTimes

func WithMaxTimes(n uint64) Option

WithMaxTimes 设置循环的最大次数.

Jump to

Keyboard shortcuts

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