Documentation ¶
Overview ¶
* * @Author: Aceld * @Date: 2019/4/30 11:57 * @Mail: danbing.at@gmail.com
* * @Author: Aceld * @Date: 2019/4/30 17:42 * @Mail: danbing.at@gmail.com
* * @Author: Aceld * @Date: 2019/5/8 17:43 * @Mail: danbing.at@gmail.com * * 时间轮调度器 * 依赖模块,delayfunc.go timer.go timewheel.go
* * @Author: Aceld * @Date: 2019/4/30 11:57 * @Mail: danbing.at@gmail.com
Index ¶
- Constants
- func UnixMilli() int64
- type DelayFunc
- type TimeWheel
- type Timer
- type TimerScheduler
- func (this *TimerScheduler) CancelTimer(tid uint32)
- func (this *TimerScheduler) CreateTimerAt(unixNano int64, f func(v ...interface{}), args []interface{}) (uint32, error)
- func (this *TimerScheduler) GetTriggerChan() chan *DelayFunc
- func (this *TimerScheduler) NewTimerAfter(duration time.Duration, f func(v ...interface{}), args []interface{}) (uint32, error)
- func (this *TimerScheduler) NewTimerInterval(duration time.Duration, times int, f func(v ...interface{}), ...) (uint32, error)
- func (this *TimerScheduler) Start()
Constants ¶
const ( HOUR_NAME = "HOUR" HOUR_INTERVAL = 60 * 60 * 1e3 //ms为精度 HOUR_SCALES = 12 MINUTE_NAME = "MINUTE" MINUTE_INTERVAL = 60 * 1e3 MINUTE_SCALES = 60 SECOND_NAME = "SECOND" SECOND_INTERVAL = 1e3 SECOND_SCALES = 60 TIMERS_MAX_CAP = 2048 //每个时间轮刻度挂载定时器的最大个数 )
const ( //默认缓冲触发函数队列大小 MAX_CHAN_BUFF = 2048 //默认最大误差时间 MAX_TIME_DELAY = 100 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DelayFunc ¶
type DelayFunc struct {
// contains filtered or unexported fields
}
定义一个延迟调用函数 延迟调用函数就是 时间定时器超时的时候,触发的事先注册好的 回调函数
func NewDelayFunc ¶
func NewDelayFunc(f func(v ...interface{}), args []interface{}) *DelayFunc
创建一个延迟调用函数
type TimeWheel ¶
type TimeWheel struct { //互斥锁(继承RWMutex的 RWLock,UnLock 等方法) sync.RWMutex // contains filtered or unexported fields }
func NewTimeWheel ¶
创建一个时间轮 name:时间轮的名称 interval:每个刻度之间的duration时间间隔 scales:当前时间轮的轮盘一共多少个刻度(如我们正常的时钟就是12个刻度) maxCap: 每个刻度所最大保存的Timer定时器个数
func (*TimeWheel) AddTimeWheel ¶
给一个时间轮添加下层时间轮 比如给小时时间轮添加分钟时间轮,给分钟时间轮添加秒时间轮
func (*TimeWheel) GetTimerWithIn ¶
获取定时器在一段时间间隔内的Timer
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
定时器实现
func NewTimerAfter ¶
创建一个定时器,在当前时间延迟duration之后触发 定时器方法
func NewTimerAt ¶
创建一个定时器,在指定的时间触发 定时器方法 df: DelayFunc类型的延迟调用函数类型 unixNano: unix计算机从1970-1-1至今经历的纳秒数
func NewTimerInterval ¶
type TimerScheduler ¶
func (*TimerScheduler) CreateTimerAt ¶
func (this *TimerScheduler) CreateTimerAt(unixNano int64, f func(v ...interface{}), args []interface{}) (uint32, error)
创建一个定点Timer 并将Timer添加到分层时间轮中, 返回Timer的tid
func (*TimerScheduler) GetTriggerChan ¶
func (this *TimerScheduler) GetTriggerChan() chan *DelayFunc
获取计时结束的延迟执行函数通道
func (*TimerScheduler) NewTimerAfter ¶
func (this *TimerScheduler) NewTimerAfter(duration time.Duration, f func(v ...interface{}), args []interface{}) (uint32, error)
创建一个延迟Timer 并将Timer添加到分层时间轮中, 返回Timer的tid