Documentation ¶
Overview ¶
Package timer 定时器,时间轮 推荐使用 timer-pool.go 中的 TimerWheelPool 而不是直接使用 TimerWheel
Index ¶
- type Handler
- type Task
- type TimerWheel
- func (tw *TimerWheel) AddCron(hour, minute, second int, times int, callback Handler) *Task
- func (tw *TimerWheel) AddMonthCron(dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
- func (tw *TimerWheel) AddTask(delay time.Duration, times int, callback Handler) *Task
- func (tw *TimerWheel) AddWeekCron(week, hour, minute, second int, times int, callback Handler) *Task
- func (tw *TimerWheel) AddYearDayCron(month, dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
- func (tw *TimerWheel) Close()
- func (tw *TimerWheel) Start()
- type TimerWheelPool
- func (twp *TimerWheelPool) AddCron(hour, minute, second int, times int, callback Handler) *Task
- func (twp *TimerWheelPool) AddMonthCron(dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
- func (twp *TimerWheelPool) AddTask(delay time.Duration, times int, callback Handler) *Task
- func (twp *TimerWheelPool) AddWeekCron(week, hour, minute, second int, times int, callback Handler) *Task
- func (twp *TimerWheelPool) AddYearDayCron(month, dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
- func (twp *TimerWheelPool) Close()
- func (twp *TimerWheelPool) Start()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task 表示一个将要执行的任务,存储于 Slot 中
type TimerWheel ¶
type TimerWheel struct {
// contains filtered or unexported fields
}
TimerWheel 时间轮
func (*TimerWheel) AddCron ¶
func (tw *TimerWheel) AddCron(hour, minute, second int, times int, callback Handler) *Task
AddCron 添加一个指定时间执行的任务
示例:每天早上 5 点执行,AddCron(5, 0, 0, -1, true, func() {})
func (*TimerWheel) AddMonthCron ¶
func (tw *TimerWheel) AddMonthCron(dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
AddMonthCron 添加一个每月指定时间执行的任务 dayOfMonth: 1-31
示例:每月 1 号早上 5 点执行,AddMonthCron(1, 5, 0, 0, -1, true, func() {})
func (*TimerWheel) AddWeekCron ¶
func (tw *TimerWheel) AddWeekCron(week, hour, minute, second int, times int, callback Handler) *Task
AddWeekCron 添加一个每周指定时间执行的任务 week: 1-7 表示周一到周七
示例:每周一早上 5 点执行,AddWeekCron(1, 5, 0, 0, -1, true, func() {})
func (*TimerWheel) AddYearDayCron ¶
func (tw *TimerWheel) AddYearDayCron(month, dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
AddYearDayCron 添加一个具体日期执行的任务 month: 1-12 dayOfMonth: 1-31
示例:每年6月1日早上 5 点执行
type TimerWheelPool ¶
type TimerWheelPool struct {
// contains filtered or unexported fields
}
TimerWheelPool 时间轮池 推荐使用,而不是直接使用 TimerWheel 可以将任务分发在多个时间轮中
func NewPool ¶
func NewPool(poolsize int, interval time.Duration, slotNum int) *TimerWheelPool
NewPool 创建一个时间轮池
func (*TimerWheelPool) AddCron ¶
func (twp *TimerWheelPool) AddCron(hour, minute, second int, times int, callback Handler) *Task
AddCron 添加一个指定时间执行的任务
示例:每天早上 5 点执行,AddCron(5, 0, 0, -1, true, func() {})
func (*TimerWheelPool) AddMonthCron ¶
func (twp *TimerWheelPool) AddMonthCron(dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
AddMonthCron 添加一个每月指定时间执行的任务 dayOfMonth: 1-31
示例:每月 1 号早上 5 点执行,AddMonthCron(1, 5, 0, 0, -1, true, func() {})
func (*TimerWheelPool) AddTask ¶
AddTask 添加一个任务 delay 延迟时间 times 重复执行次数,-1 表示永久重复执行 callback 时间到之后的回调
func (*TimerWheelPool) AddWeekCron ¶
func (twp *TimerWheelPool) AddWeekCron(week, hour, minute, second int, times int, callback Handler) *Task
AddWeekCron 添加一个每周指定时间执行的任务 week: 1-7 表示周一到周七
示例:每周一早上 5 点执行,AddWeekCron(1, 5, 0, 0, -1, true, func() {})
func (*TimerWheelPool) AddYearDayCron ¶
func (twp *TimerWheelPool) AddYearDayCron(month, dayOfMonth, hour, minute, second int, times int, callback Handler) *Task
AddYearDayCron 添加一个具体日期执行的任务 month: 1-12 dayOfMonth: 1-31
示例:每年6月1日早上 5 点执行
func (*TimerWheelPool) Close ¶
func (twp *TimerWheelPool) Close()
func (*TimerWheelPool) Start ¶
func (twp *TimerWheelPool) Start()