Help us shape the future of Go! Take the 2026 Go Developer Survey

timer

package
v1.12.11 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

func Register

func Register(task ITask) error

注册定时任务

func SetObject

func SetObject(oj *Timer)

Types

type Component

type Component struct {
	Object *Timer
}

func (*Component) Close

func (d *Component) Close()

func (*Component) Init

func (d *Component) Init(data map[string]any) error

初始化

type Config

type Config struct {
	Size               int   `yaml:"size"`                  // 时间轮数量
	MinPeriodBitNumber int64 `yaml:"min_period_bit_number"` // 定时器最小周期
}

type ITask

type ITask interface {
	IsEnable() bool   // 是否可用
	GetTTL() int64    // 获取有效时长
	GetExpire() int64 // 任务触发时间点
	Refresh(int64)    // 刷新任务触发时间点
	Call()            // 执行任务
}

type ITimer

type ITimer interface {
	Init(*Config) error
	Close()
	Register(ITask) error
}

type Task

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

func NewTask

func NewTask(id *uint64, ttl time.Duration, times int32, f func()) *Task

func (*Task) Call

func (d *Task) Call()

func (*Task) GetExpire

func (d *Task) GetExpire() int64

func (*Task) GetTTL

func (d *Task) GetTTL() int64

func (*Task) IsEnable

func (d *Task) IsEnable() bool

func (*Task) Refresh

func (d *Task) Refresh(now int64)

func (*Task) String

func (d *Task) String() string

type Timer

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

func GetObject

func GetObject() *Timer

func NewTimer

func NewTimer[T ITimer](f func() T) *Timer

func (*Timer) Close

func (d *Timer) Close()

func (*Timer) Init

func (d *Timer) Init(cfg *Config) error

func (*Timer) Register

func (d *Timer) Register(task ITask) error

Directories

Path Synopsis
adapter

Jump to

Keyboard shortcuts

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