timewheel

package
v1.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(t *Task)

Option 时间轮任务选项

func WithAttempts

func WithAttempts(attempts uint16) Option

WithAttempts 指定任务重试次数;默认:1

func WithDelay added in v1.12.2

func WithDelay(fn func(attempts uint16) time.Duration) Option

WithDelay 指定任务延迟执行时间;默认:立即执行

type Task

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

Task 时间轮任务

type TimeWheel

type TimeWheel interface {
	// AddTask 添加一个任务,到期被执行,默认仅执行一次;若指定了重试次数,则在返回`error`后重试;
	// 注意:任务是异步执行的,`ctx`一旦被取消,则任务也随之取消;如要保证任务不被取消,可以使用`yiigo.DetachContext`(如果您的Go版本>=1.21.0,请使用 `context.WithoutCancel`)
	AddTask(ctx context.Context, taskID string, fn func(ctx context.Context, taskID string) error, options ...Option)
	// Run 运行时间轮
	Run()
	// Stop 终止时间轮
	Stop()
}

TimeWheel 单时间轮

func New

func New(tick time.Duration, size int) TimeWheel

New 返回一个时间轮实例

Jump to

Keyboard shortcuts

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