timer

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const C_TIMER_TICK_INTERVAL = 100 * time.Millisecond // 定时器默认tick精度

Variables

This section is empty.

Functions

This section is empty.

Types

type ITimer

type ITimer interface {

	// 启动
	StartTimer(restorer ...ITimerRestorer)

	// 关闭
	CloseTimer()

	// 添加定时器[当handle返回false时自动删除此TimerHandler]
	AddTimer(d time.Duration, handle TTimerHandFunc, opt ...*TimerOpt)

	// 添加每天一次的定时器[同上](after0:每天超过零点多少时间)
	AddDailyTimer(after0 time.Duration, handle TTimerHandFunc, opt ...*TimerOpt)

	// 移除定时器
	DelTimer(handle TTimerHandFunc)
	DelTimerByName(name string)
}

定时器接口

func NewTimer

func NewTimer(tickerInterval ...time.Duration) ITimer

type ITimerRestorer

type ITimerRestorer interface {

	// 恢复状态
	Load() map[string]int64

	// 保存状态
	Save(key string, valAt int64)
}

状态存储接口

type TTimerHandFunc

type TTimerHandFunc func(now time.Time) (keep bool)

type TimerOpt

type TimerOpt struct {
	Name  string // 自定义名称(默认为函数名util.FuncFullNameRef)
	Right bool   // 是否立刻执行(daily类:当天时间满足的话则执行)
	Store bool   // 是否需要保存状态
}

==================== TimerOpt(可选参数)

Jump to

Keyboard shortcuts

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