From 8d7bf727eff921e7b2a162b247d5c02d14845f9a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 26 Oct 2020 10:12:18 +0800 Subject: [PATCH] 1 --- app.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 6161d9b..a15a9ce 100644 --- a/app.go +++ b/app.go @@ -21,6 +21,7 @@ type App_ struct { imWorkNode *IMMsgNode imMsgMutex sync.RWMutex chGoLoopTimerExit chan int + chGoLoopWait chan int64 nowTime time.Time imMsgHandlers [1024]func(int16,*q5.XParams) } @@ -53,6 +54,7 @@ func (this *App_) Init() { flag.Parse() this.loopCond = sync.NewCond(new(sync.Mutex)) this.chGoLoopTimerExit = make(chan int) + this.chGoLoopWait = make(chan int64) go this.goLoopTimer() } @@ -118,17 +120,24 @@ func (this *App_) RegisterIMMsgHandle(msgId int16, handle func(int16,*q5.XParams } func (this *App_) goLoopTimer() { + var waitMs int64 = 1000 * 10 for { select { case <-this.chGoLoopTimerExit: return - case <-time.After(time.Millisecond): + case waitMs = <-this.chGoLoopWait: + if waitMs < 1 { + waitMs = 1 + } + case <-time.After(time.Millisecond * time.Duration(waitMs)): + waitMs = 1000 * 10 this.loopCond.Broadcast() } } } func (this *App_) schedule() { + this.chGoLoopWait <- Timer().GetIdleTime() this.loopCond.L.Lock() this.loopCond.Wait() this.loopCond.L.Unlock()