74 lines
1.4 KiB
Go
74 lines
1.4 KiB
Go
|
|
package coroutine_timer
|
||
|
|
|
||
|
|
// timersModel
|
||
|
|
// @description: timer卡槽对象
|
||
|
|
type timersModel struct {
|
||
|
|
timers map[string]*timerObj
|
||
|
|
}
|
||
|
|
|
||
|
|
// newTimersModel
|
||
|
|
// @description: 构造timer卡槽对象
|
||
|
|
// parameter:
|
||
|
|
// return:
|
||
|
|
// @*timersModel:
|
||
|
|
func newTimersModel() *timersModel {
|
||
|
|
return &timersModel{timers: map[string]*timerObj{}}
|
||
|
|
}
|
||
|
|
|
||
|
|
// addTimer
|
||
|
|
// @description: 添加定时器
|
||
|
|
// parameter:
|
||
|
|
// @receiver this:
|
||
|
|
// @t:
|
||
|
|
// return:
|
||
|
|
func (this *timersModel) addTimer(t *timerObj) {
|
||
|
|
this.timers[t.id] = t
|
||
|
|
}
|
||
|
|
|
||
|
|
// delTimer
|
||
|
|
// @description: 删除定时器
|
||
|
|
// parameter:
|
||
|
|
// @receiver this:
|
||
|
|
// @id:
|
||
|
|
// return:
|
||
|
|
func (this *timersModel) delTimer(id string) {
|
||
|
|
delete(this.timers, id)
|
||
|
|
}
|
||
|
|
|
||
|
|
// exist
|
||
|
|
// @description: 判断id是否存在
|
||
|
|
// parameter:
|
||
|
|
// @receiver this:
|
||
|
|
// @id:
|
||
|
|
// return:
|
||
|
|
// @exist:
|
||
|
|
func (this *timersModel) exist(id string) (exist bool) {
|
||
|
|
_, exist = this.timers[id]
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// getAllTimers
|
||
|
|
// @description: 获取所有定时器
|
||
|
|
// parameter:
|
||
|
|
// @receiver this:
|
||
|
|
// return:
|
||
|
|
// @map[string]*timerObj:
|
||
|
|
func (this *timersModel) getAllTimers() map[string]*timerObj {
|
||
|
|
return this.timers
|
||
|
|
}
|
||
|
|
|
||
|
|
// getAllTimers2
|
||
|
|
// @description: 获取所有定时器
|
||
|
|
// parameter:
|
||
|
|
// @receiver this:
|
||
|
|
// return:
|
||
|
|
// @result:
|
||
|
|
func (this *timersModel) getAllTimers2() (result []*timerObj) {
|
||
|
|
result = make([]*timerObj, 0, len(this.timers))
|
||
|
|
for _, v := range this.timers {
|
||
|
|
result = append(result, v)
|
||
|
|
}
|
||
|
|
|
||
|
|
return
|
||
|
|
}
|