1 Star 0 Fork 0

zjh-tech / go-etimer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
extend_timer_mgr.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
zjh-tech 提交于 2023-08-02 13:40 . init
package etimer
import (
"container/list"
"context"
"sync"
"time"
"go.uber.org/atomic"
)
type ExtendTimerMgr struct {
uid atomic.Int64
triggerQueue chan *ExtendTimer
ctxWithCancel context.Context
cancelFunc context.CancelFunc
wg sync.WaitGroup
closeFlag bool
lastMillSec int64
millSecTimerList *list.List
minTimerList *list.List
}
func NewExtendTimerMgr(triggerQueueSize int) *ExtendTimerMgr {
return &ExtendTimerMgr{
uid: *atomic.NewInt64(0),
triggerQueue: make(chan *ExtendTimer, triggerQueueSize),
}
}
func (u *ExtendTimerMgr) Init(ctx context.Context) {
u.ctxWithCancel, u.cancelFunc = context.WithCancel(ctx)
}
func (u *ExtendTimerMgr) UnInit() {
if u.closeFlag {
return
}
u.closeFlag = true
if u.cancelFunc != nil {
u.cancelFunc()
u.wg.Wait()
u.cancelFunc = nil
}
}
func (u *ExtendTimerMgr) AddOnceTimer(d time.Duration, cb FuncType, args ArgType) *ExtendTimer {
uid := u.uid.Add(1)
extendTimer := newExtendTimer(uid, cb, args, false)
return extendTimer
}
func (u *ExtendTimerMgr) GetExtendTimerTriggerChannel() chan *ExtendTimer {
return u.triggerQueue
}
func (u *ExtendTimerMgr) ExecExtendTimerTriggerLogic(timer *ExtendTimer) {
if timer.state != TimerRunningState {
return
}
timer.Call()
timer.SetInvalid()
}
Go
1
https://gitee.com/zjh-tech/go-etimer.git
git@gitee.com:zjh-tech/go-etimer.git
zjh-tech
go-etimer
go-etimer
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891