timewheel

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CtxErrFn

type CtxErrFn func(ctx context.Context, taskId string, err error)

CtxErrFn 任务 context「取消/超时」的处理方法

type Option

type Option func(tw *timewheel)

Option 时间轮选项

func WithCtxErrFn

func WithCtxErrFn(fn CtxErrFn) Option

func WithPanicFn

func WithPanicFn(fn PanicFn) Option

WithPanicFn 指定任务执行Panic的处理方法

type PanicFn

type PanicFn func(ctx context.Context, taskId string, err any, stack []byte)

PanicFn 任务发生Panic的处理方法

type TaskFn

type TaskFn func(ctx context.Context, taskId string, attempts int64) time.Duration

TaskFn 任务方法,返回下一次执行的延迟时间,若返回0,则表示不再执行

type TimeWheel

type TimeWheel interface {
	// Go 异步一个任务并返回任务ID;
	// 注意:任务是异步执行的,`ctx`一旦被取消/超时,则任务也随之取消;
	// 如要保证任务不被取消,请使用`context.WithoutCancel`
	Go(ctx context.Context, taskFn TaskFn, delay time.Duration) string

	// Stop 终止时间轮
	Stop()
}

TimeWheel 单层时间轮

func New

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

New 返回一个时间轮实例

Jump to

Keyboard shortcuts

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